Skip to content

Commit

Permalink
fixes #430
Browse files Browse the repository at this point in the history
  • Loading branch information
seperman committed Nov 14, 2023
1 parent 2178878 commit 32182c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions deepdiff/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _add_to_elements(elements, elem, inside):
return
if not elem.startswith('__'):
remove_quotes = False
if '\\' in elem:
if '𝆺𝅥𝅯' in elem or '\\' in elem:
remove_quotes = True
else:
try:
Expand Down Expand Up @@ -62,7 +62,7 @@ def _path_to_elements(path, root_element=DEFAULT_FIRST_ELEMENT):
inside_quotes = False
quote_used = ''
for char in path:
if prev_char == '\\':
if prev_char == '𝆺𝅥𝅯':
elem += char
elif char in {'"', "'"}:
elem += char
Expand Down Expand Up @@ -270,12 +270,11 @@ def parse_path(path, root_element=DEFAULT_FIRST_ELEMENT, include_actions=False):
def stringify_element(param, quote_str=None):
has_quote = "'" in param
has_double_quote = '"' in param
if has_quote and has_double_quote:
if has_quote and has_double_quote and not quote_str:
new_param = []
for char in param:
if char in {'"', "'"}:
import pytest; pytest.set_trace()
new_param.append('\\')
new_param.append('𝆺𝅥𝅯')
new_param.append(char)
result = '"' + ''.join(new_param) + '"'
elif has_quote:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_diff_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_diff_quote_and_double_quote_in_string(self):
t1 = {'''a'"a''': 1}
t2 = {'''a'"a''': 2}
diff = DeepDiff(t1, t2)
expected = {'values_changed': {"root['a\\'\\\"a']": {'new_value': 2, 'old_value': 1}}}
expected = {'values_changed': {'root["a\'"a"]': {'new_value': 2, 'old_value': 1}}}
assert expected == diff

def test_bytes(self):
Expand Down

0 comments on commit 32182c8

Please sign in to comment.