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

V15: Rich Text Editor links do not work with query strings and anchors #17288

Merged
merged 6 commits into from
Oct 16, 2024

Conversation

iOvergaard
Copy link
Contributor

@iOvergaard iOvergaard commented Oct 16, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes #17219
Fixes #17272
Partly fixes #17009 (which still needs a frontend fix)

Description

Since the change from UDIs to "localLinks" in the href attribute (>=14.1), the pattern matched a little too much in the href section completely ignoring any "extras" such as query strings and anchors after the locallink, which meant that the locallink did not get replaced at all if they were present. This is fixed by limiting the regexp a bit.

Because we are no longer matching the whole href attribute but only some of its contents, we need to fix the old pattern. It has been simplified into a main RegExp that finds all a-tags with local links inside, then another regex is run on each component subset to find its type attribute value.

I have added more test cases to cover what did not work before. In general, the two paradigms of rich text pattern matching should be:

  1. The order of attributes should not matter
  2. The only part of the link that should be replaced is {localLink:<GUID|INT>} leaving all other parts to itself

This means that links like the following now work:

<a type="document" href="/{localLink:9931BDE0-AAC3-4BAB-B838-909A7B47570E}#anchor">Link with anchor</a>

<a type="document" href="/{localLink:9931BDE0-AAC3-4BAB-B838-909A7B47570E}?v=1">Link with query</a>

<a title="My title" rel="noreferer" type="document" href="/{localLink:9931BDE0-AAC3-4BAB-B838-909A7B47570E}">Link with other attributes</a>

<a 
  type="document"
  href="/{localLink:9931BDE0-AAC3-4BAB-B838-909A7B47570E}#anchor">
  Link with anchor
</a>

Since the change from UDIs to localLinks in href, the pattern matched a little too much in the href section completely ignoring any "extras" such as querystrings and anchors after the locallink, which meant that the locallink did not get replaced at all if they were present. This is fixed by limiting the regexp a bit.
Because we are now no longer matching the whole `href` attribute but only some of its contents, we need to fix up the old pattern as well. It has been extended with matching groups that follow the same pattern as the new links.
Copy link
Member

@leekelleher leekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to say that we've got there with this one! 😅
Tested out with various scenarios for both TinyMCE and Tiptap RTE editors, I'm happy with the results. Great work on the RegEx, (it made my head hurt). 🚀

@iOvergaard iOvergaard merged commit 35e8f2e into release/15.0 Oct 16, 2024
4 of 6 checks passed
@iOvergaard iOvergaard deleted the v15/hotfix/html-locallinks-extras branch October 16, 2024 14:53
iOvergaard added a commit that referenced this pull request Oct 17, 2024
#17288)

* fix: anchors and query strings do not work

Since the change from UDIs to localLinks in href, the pattern matched a little too much in the href section completely ignoring any "extras" such as querystrings and anchors after the locallink, which meant that the locallink did not get replaced at all if they were present. This is fixed by limiting the regexp a bit.

* fix: legacy links do not follow the same regexp as new links

Because we are no longer matching the whole `href` attribute but only some of its contents, we need to fix up the old pattern. It has been extended with matching groups that follow the same pattern as the new links.

* feat: allow a-tags to be multiline

example:

```html
<a
  type="document"
  href="/{localLink:<GUID>}">
Test
</a>
```

* fix: split regex into two parts: first a tokenizer for a-tags and then a type-finder

* fix: ensure only "document" and "media" are matching to speed up the pattern

* feat: allow a-tags to be multiline

(cherry picked from commit 35e8f2e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants