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

Fix serializer block with anchors, remove trailing slash before the anchor #1748

Merged
merged 5 commits into from
Feb 15, 2024
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
1 change: 1 addition & 0 deletions news/1748.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an edge case in the blocks resolveuid transforms with a trailing slash before a fragment. @sneridagh
2 changes: 1 addition & 1 deletion src/plone/restapi/deserializer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def path2uid(context, link):
suffix = ""
match = PATH_RE.match(path)
if match is not None:
path = match.group(1)
path = match.group(1).rstrip("/")
suffix = match.group(2) or ""

obj = portal.unrestrictedTraverse(path, None)
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/serializer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re


RESOLVEUID_RE = re.compile("^(?:|.*/)resolve[Uu]id/([^/#]*)/?(.*)?$")
RESOLVEUID_RE = re.compile("^(?:|.*/)resolve[Uu]id/([^/#]*)?(.*)?$")


def resolve_uid(path):
Expand All @@ -29,7 +29,7 @@ def resolve_uid(path):
return path, None
href = brain.getURL()
if suffix:
return href + "/" + suffix, brain
return href + suffix, brain
target_object = brain._unrestrictedGetObject()
adapter = queryMultiAdapter(
(target_object, target_object.REQUEST),
Expand Down
30 changes: 30 additions & 0 deletions src/plone/restapi/tests/test_blocks_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,36 @@ def test_slate_simple_link_deserializer_with_suffix_and_anchor(self):
link, f"../resolveuid/{self.image.UID()}/@@download/file#anchor-id"
)

def test_slate_simple_link_deserializer_with_slash_and_anchor(self):
blocks = {
"abc": {
"@type": "slate",
"plaintext": "Frontpage content here",
"value": [
{
"children": [
{"text": "Frontpage "},
{
"children": [{"text": "content "}],
"data": {
"url": "%s/image-1/#anchor-id"
% self.portal.absolute_url()
},
"type": "link",
},
{"text": "here"},
],
"type": "h2",
}
],
}
}

res = self.deserialize(blocks=blocks)
value = res.blocks["abc"]["value"]
link = value[0]["children"][1]["data"]["url"]
self.assertEqual(link, f"../resolveuid/{self.image.UID()}#anchor-id")

def test_aquisition_messing_with_link_deserializer(self):
self.portal.invokeFactory(
"Folder",
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/test_blocks_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_simple_link_serializer_with_anchor(self):
)
value = res["abc"]["value"]
link = value[0]["children"][1]["data"]["url"]
self.assertEqual(link, f"{self.portal['doc1'].absolute_url()}/#anchor-id")
self.assertEqual(link, f"{self.portal['doc1'].absolute_url()}#anchor-id")

def test_simple_link_serializer_with_suffix(self):
doc_uid = IUUID(self.portal["doc1"])
Expand Down
Loading