Fix detection of URLs in markdown selection
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
- Go to a new note (e.g. in an Issue)
- Type in text like
group::label
and either click the link icon in the toolbar, orCMD + K
- Outcome:
- Before this fix:
[text](group::label)
- After this fix:
[group::label](url)
- Before this fix:
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.