Skip to content

Commit cc0e457

Browse files
committed
BREAK(jsonp) empty path => empty-parts ...
bc standard is not involved with *parts*.
1 parent a15bb95 commit cc0e457

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

graphtik/jsonpointer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def jsonp_path(jsonpointer: str) -> List[str]:
149149
150150
>>> jsonp_path('/')
151151
['']
152-
>>> jsonp_path('') # this becomes also root!
153-
['']
152+
>>> jsonp_path('')
153+
[]
154154
155155
>>> jsonp_path('a/b//c')
156156
['', 'c']
@@ -162,6 +162,12 @@ def jsonp_path(jsonpointer: str) -> List[str]:
162162
if parts is False:
163163
parts = [jsonpointer]
164164
elif parts is None:
165+
## For empty-paths, the jsonpointer standard specifies
166+
# they must return the whole document (satisfied by `resolve_path()`)
167+
# but not what their *parts* should be.
168+
if jsonpointer == "":
169+
return []
170+
165171
parts = [
166172
unescape_jsonpointer_part(part)
167173
for part in re.sub(".+(?:/$|/{2})", "/", jsonpointer).split("/")

test/test_jsonpointer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def un_esc(part):
3838

3939

4040
def test_jsonp_path_empty():
41-
assert jsonp_path("") == [""]
41+
assert jsonp_path("") == []
4242

4343

4444
def test_jsonp_path_root():
@@ -92,7 +92,6 @@ class C(str):
9292
("/a//b", ["a", "", "b"]),
9393
("/a/../b", ["a", "..", "b"]),
9494
("/", [""]),
95-
("", []),
9695
("/ some ", [" some "]),
9796
("/ some /", [" some ", ""]),
9897
("/ some / ", [" some ", " "]),
@@ -118,7 +117,6 @@ def test_jsonp_path_massive(inp, exp):
118117
("/a/b/", [""]),
119118
("/a//b", ["", "b"]),
120119
("/", [""]),
121-
("", [""]),
122120
("/ some ", ["", " some "]),
123121
("/ some /", [""]),
124122
("/ some / ", ["", " some ", " "]),

0 commit comments

Comments
 (0)