File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
localstack_snapshot/snapshots Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
+ import re
2
3
3
4
from localstack_snapshot .snapshots import SnapshotMatchResult
4
5
29
30
"underlined" : 4 ,
30
31
}
31
32
33
+ _regular_json_path_chars_regex = re .compile ("[a-zA-Z0-9_-]+" )
34
+
32
35
33
36
class PatchPath (str ):
34
37
"""
@@ -52,7 +55,11 @@ def _format_json_path(path: list):
52
55
json_str = "$.."
53
56
for idx , elem in enumerate (path ):
54
57
if not isinstance (elem , int ):
55
- json_str += str (elem )
58
+ _elem = str (elem )
59
+ # we want to wrap in single quotes parts with special characters so that users can copy-paste them directly
60
+ if not _regular_json_path_chars_regex .fullmatch (_elem ):
61
+ _elem = f"'{ _elem } '"
62
+ json_str += _elem
56
63
if idx < len (path ) - 1 and not json_str .endswith (".." ):
57
64
json_str += "."
58
65
Original file line number Diff line number Diff line change @@ -209,6 +209,14 @@ def test_json_diff_format():
209
209
assert _format_json_path (path ) == '"$.."'
210
210
path = [1 , 1 , 0 , "SomeKey" ]
211
211
assert _format_json_path (path ) == '"$..SomeKey"'
212
+ path = ["Some:Key" ]
213
+ assert _format_json_path (path ) == "\" $..'Some:Key'\" "
214
+ path = ["Some.Key" ]
215
+ assert _format_json_path (path ) == "\" $..'Some.Key'\" "
216
+ path = ["Some-Key" ]
217
+ assert _format_json_path (path ) == '"$..Some-Key"'
218
+ path = ["Some0Key" ]
219
+ assert _format_json_path (path ) == '"$..Some0Key"'
212
220
213
221
214
222
def test_sorting_transformer ():
You can’t perform that action at this time.
0 commit comments