Skip to content

Fix detection of URLs in markdown selection

Nicolas Dular requested to merge nd/fix-markdown-url-generation into master

What does this MR do and why?

Issue: #360764 (closed)

When creating a link in markdown (either via the shortcut or the toolbar button) we try to detect if the selected text is already a URL.

Depending on the text being a URL or not, we either use the content of the selection as the text or url part of the generated markdown.

Before this change, we only created an instance of URL and checked if it worked. However, just because we are able to create an instance of URL it doesn't mean the content is actually a valid URL.

e.g. new URL('group::label') initializes a URL object.

As it's common in GitLab to use : in text (e.g. for grouped labels) we detected that group::label is a valid URL, which is a sub-optimal user experience.

With this change we're more conservative as we not only check if the URL object got created, but also if it contains a valid value

Screenshots or screen recordings

Before After
before_fix after_fix

How to set up and validate locally

  1. Go to a new note (e.g. in an Issue)
  2. Type in text like group::label and either click the link icon in the toolbar, or CMD + K
  3. Outcome:
    1. Before this fix: [text](group::label)
    2. After this fix: [group::label](url)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Nicolas Dular

Merge request reports