Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removed escape of forward slash in json files #2005

Merged
merged 4 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog

* Fixed a bug where any edited json file that contained a forward slash (`/`) escaped.
* Added a new validation to **validate** command to verify that the metadata *currentVersion* is
the same as the last release note version.
* **Breaking change**: Fixed a typo in the **validate** `--quiet-bc-validation` flag (was `--quite-bc-validation`). @upstart-swiss
Expand Down
11 changes: 9 additions & 2 deletions demisto_sdk/commands/common/handlers/json/ujson_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def load(self, fp: IO[str]):

def dump(self, obj: Any, fp: IO[str], indent=0, sort_keys=False):
try:
ujson.dump(obj, fp, indent=indent, sort_keys=sort_keys)
ujson.dump(
obj,
fp,
indent=indent,
sort_keys=sort_keys,
escape_forward_slashes=False
)
except ValueError as e:
raise JSONDecodeError(e)

Expand All @@ -42,7 +48,8 @@ def dumps(self, obj: Any, indent=0, sort_keys=False):
return ujson.dumps(
obj,
sort_keys=sort_keys,
indent=indent
indent=indent,
escape_forward_slashes=False
)
except ValueError as e:
raise JSONDecodeError(e)
22 changes: 22 additions & 0 deletions demisto_sdk/commands/common/handlers/tests/json_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from demisto_sdk.commands.common.handlers import JSON_Handler


class TestJSONHandler:
@pytest.mark.parametrize('slash_count', range(4))
def test_no_escape_chars_dumps(self, slash_count: int):
"""Check that a dumped json has no escape chars"""
slashes = '/' * slash_count
url = f'https:{slashes}xsoar.com'
dumped = JSON_Handler().dumps({'url': url})
assert url in dumped, 'Could not find the url in the dumped file. Maybe escaped char?'

@pytest.mark.parametrize('slash_count', range(4))
def test_no_escape_chars_dump(self, tmpdir, slash_count: int):
"""Check that a dumped json has no escape chars"""
file_ = tmpdir / 'file.json'
slashes = '/' * slash_count
url = f'https:{slashes}xsoar.com'
JSON_Handler().dump({'url': url}, file_.open('w+'))
assert url in file_.open().read()