Skip to content

Commit

Permalink
feat: add comment why we should use replace in value configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Romazes committed Aug 21, 2024
1 parent 88c8f54 commit 248c203
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lean/models/json_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def get_settings(self) -> Dict[str, str]:
for key, value in configuration._value.items():
settings[key] = str(value)
else:
# Replace escaped newline characters and backslashes in the configuration value.
# When reading the JSON configuration through Python, newline characters ('\n') and backslashes ('\')
# may be escaped, causing issues in scenarios where these characters are expected to be interpreted
# literally (e.g., file paths, multi-line strings). This replace operation ensures that:
# 1. Escaped newline characters ('\\n') are correctly interpreted as actual newlines ('\n').
# 2. Backslashes ('\\') in file paths are converted to forward slashes ('/'), making paths
# more consistent across different operating systems.
settings[configuration._id] = str(configuration._value).replace("\\n", "\n").replace("\\", "/")

return settings
Expand Down

0 comments on commit 248c203

Please sign in to comment.