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

LinkControl - improve "valid entry" matching (not always a URL!) #19629

Closed
getdave opened this issue Jan 14, 2020 · 3 comments · Fixed by #19823
Closed

LinkControl - improve "valid entry" matching (not always a URL!) #19629

getdave opened this issue Jan 14, 2020 · 3 comments · Fixed by #19823
Assignees
Labels
[Block] Navigation Affects the Navigation Block [Type] Question Questions about the design or development of the editor.

Comments

@getdave
Copy link
Contributor

getdave commented Jan 14, 2020

Originally posted by @WunderBart in #19458 (comment)

I don't think we should suggest creating a link out of (almost) any string as it can often lead to creating invalid URLs. Instead, we could validate the value while typing and suggest creating a nav link with it only when it's a valid URL. The validation could be done using the URL constructor, like this:

function isValidURL(string) {
  try {
    new URL(string);
    return true;
  } catch (_) {
    return false;  
  }
}

We'd also have more control over what we want to render as a link title using created URL object properties.
I've made a simple fiddle with the validation demo: https://jsfiddle.net/wunderbart/xn01pscd/

Notes

This might not be as simple as outlined above because we need to account for entries including:

  • mailto:
  • tel
  • #internal-anchors`

None of these pass the new URL() test.

@WunderBart I'm all for improving the "valid entry" logic but we need to be mindful that valid input isn't only pure URLs.

@getdave getdave added [Block] Navigation Affects the Navigation Block [Type] Question Questions about the design or development of the editor. labels Jan 14, 2020
@getdave getdave changed the title LinkControl - Create links only when the input value is a valid URL LinkControl - improve "valid entry" matching (not always a URL!) Jan 14, 2020
@WunderBart
Copy link
Member

WunderBart commented Jan 14, 2020

Thanks for creating the issue, @getdave.

None of these pass the new URL() test.

I ran each one of those through new URL() and they all returned as valid URLs:

new URL("mailto:[email protected]")
// -> URL {href: "mailto:name@domain.com"", ...

new URL("tel:123123123")
// -> URL {href: "tel:123123123", ...

new URL("#anchor-test")
// -> URL {href: "about:blank#anchor-test", ...

Did it throw errors for you?

@getdave
Copy link
Contributor Author

getdave commented Jan 21, 2020

@WunderBart We might need this in place to properly achieve the requirements for #18900 so let's keep an eye on it.

@aduth
Copy link
Member

aduth commented Jan 30, 2020

I marked #19823 as closing this issue. Let me know if that's not correct (or feel free to edit the pull request comment to remove the auto-closing text).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants