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: Properly rewrite rich text with mixed links #11959

Closed
wants to merge 3 commits into from

Conversation

chosak
Copy link
Member

@chosak chosak commented May 16, 2024

The bulk rich text link rewriter logic introduced in #5875 doesn't work properly if the rich text contains multiple link types where one of those types doesn't need to be rewritten (for example external links like <a href="https://wagtail.org/">).

This commit fixes that bug by handling these cases, and adds additional unit tests to cover the failure cases.

Fixes #11957.

The bulk rich text link rewriter logic introduced in PR 5875 doesn't
work properly if the rich text contains multiple link types where one
of those types doesn't need to be rewritten (for example external
links like <a href="https://wagtail.org/">).

This commit fixes that bug by handling these cases, and adds additional
unit tests to cover the failure cases.

Fixes issue 11957.
Copy link

squash-labs bot commented May 16, 2024

Manage this branch in Squash

Test this branch here: https://chosakfixmixed-link-rewriter-q3jbe.squash.io

@laymonage laymonage added this to the 6.1.1 milestone May 17, 2024
@gasman
Copy link
Collaborator

gasman commented May 17, 2024

Thanks @chosak! I see the second issue mentioned on #11957, where a custom LinkHandler is in use, is still present - I think this might be a separate bug, since it involves the replacement tag being written in the wrong place entirely, rather than just URLs being switched around.

@chosak
Copy link
Member Author

chosak commented May 17, 2024

Thanks @gasman! I've just pushed a fix and test for that issue as well.

@gasman
Copy link
Collaborator

gasman commented May 17, 2024

Thanks @chosak! I'm happy with the updated logic, although still concerned that the "zipping tuples of dicts" approach is rather hard to follow, and probably largely responsible for these bugs sneaking in in the first place...

I've now had a go at refactoring it by introducing a TagMatch object to encapsulate all the information for an individual tag - please let me know what you think.

@chosak
Copy link
Member Author

chosak commented May 17, 2024

@gasman works for me! This is a nice way to make the logic more straightforward, thank you.

@gasman
Copy link
Collaborator

gasman commented May 17, 2024

Thanks @chosak! Merged in bf3f87b (main) / 729acab (stable/6.1.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Result of expand_db_html for a mixture of internal / external links is malformed
3 participants