Provide option to replace all occurrences of a URL

Created on 17 June 2024, 5 months ago

Problem/Motivation

The filter currently only replaces URLs in <a> and <img> tags. It would be ideal if there were an option to replace all occurrences.

Steps to reproduce

- Enable the module
- Enable filter in text format and add the following in settings:
-- Original: https://www.example.com
-- Replacement: %baseurl
- Create a node with the following markup: <a href="https://www.example.com/about-us">https://www.exampe.com/about-us</a>
- Save and notice that the markup is changed to <a href="/about-us">https://www.exampe.com/about-us</a>. However, it would be ideal if there were an option to change the markup to <a href="/about-us">/about-us</a>

Proposed resolution

Add a checkbox under the filter settings to "Replace all occurrences"

Remaining tasks

- Review proposed solution
- Add tests

User interface changes

- Adds a checkbox to filter settings

API changes

None

Data model changes

✨ Feature request
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States henokmikre

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @henokmikre
  • Status changed to Postponed: needs info 5 months ago
  • πŸ‡«πŸ‡·France fgm Paris, France

    Not strictly against doing this, but it raises a number of security issues around escaping content which is an an unknown parsing context instead of being only in restricted attributes on specific elements.

    Do you have a plan about how to it safely ? Consider that URLs may happen in text nodes, in HTML comments, in CDATA or PCDATA, in embedded JS, in CSS, etc. And all of those have different parsing rules.

    I'm not convinced this can be done safely in all these contexts while maintaining a reasonable complexity level.

    Alternatively, we might want to enable specific opt-in contexts, say for example the src attribute on link elements within the page head. Would this be appropriate for you ? If so, do you think you could imagine a UI for this ? Just a wireframe would be enough since we use the admin theme anyway. I'm not good at UI design at all.

    Also, I think this could be at the global level, possibly overridable per-format, as envisioned on ✨ Need for global settings - reduce Postponed: needs info

Production build 0.71.5 2024