Skip to content

Commit 90bf9dd

Browse files
authored
Do not break path2uid with strange links (#1428)
* handle edge-case in path2uid * handle edge-case in path2uid * add changelog
1 parent a80b337 commit 90bf9dd

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

news/1428.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Do not break path2uid with some edge-cases.
2+
[cekk]

src/plone/restapi/deserializer/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ def path2uid(context, link):
3030
suffix = ""
3131
while not IUUIDAware.providedBy(obj):
3232
obj = aq_parent(obj)
33+
if obj is None:
34+
break
3335
suffix += "/" + segments.pop()
3436
# check if obj is wrong because of acquisition
35-
if "/".join(obj.getPhysicalPath()) != "/".join(segments):
37+
if not obj or "/".join(obj.getPhysicalPath()) != "/".join(segments):
3638
return link
3739
href = relative_up * "../" + "resolveuid/" + IUUID(obj)
3840
if suffix:

src/plone/restapi/tests/test_blocks_deserializer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,23 @@ def test_aquisition_messing_with_link_deserializer(self):
417417
self.portal.doc1.blocks["123"]["href"][0]["@id"],
418418
f"../resolveuid/{wrong_uid}",
419419
)
420+
421+
# another use-case: pass "../.." as link. Do not change the link.
422+
self.deserialize(
423+
blocks={
424+
"123": {
425+
"@type": "foo",
426+
"href": [
427+
{
428+
# Pointing to a not created yet object, but matches because acquisition
429+
# with another existing parent content with alike-ish path structure
430+
"@id": "../.."
431+
}
432+
],
433+
}
434+
}
435+
)
436+
self.assertEqual(
437+
self.portal.doc1.blocks["123"]["href"][0]["@id"],
438+
"../..",
439+
)

0 commit comments

Comments
 (0)