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

Add support for skipping wildcard URLs #38

Closed
wants to merge 1 commit into from
Closed

Conversation

mre
Copy link
Contributor

@mre mre commented May 1, 2022

URLs can contain wildcards as in http://*.example.org.
These are commonly used in cases where listing all possible URLs would
not be feasible, e.g. when defining Content-Security-Policy rules 1.

It can be surprising to users of linkify that these URLs get extracted.
As such, this change adds support for disabling the extraction of wildcard
URLs.

Fixes #37.

URLs can contain wildcards as in http://*.example.org.
These are commonly used in cases where listing all possible URLs would
not be feasible, e.g. when defining Content-Security-Policy rules [1].

It can be surprising to users of linkify that these URLs get extracted.
As such, this change adds support for disabling the extraction of wildcard
URLs.

[1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
@mre mre changed the title Add support for skipping wildcard URLs (fixes #37) Add support for skipping wildcard URLs May 1, 2022
Copy link
Owner

@robinst robinst left a comment

Choose a reason for hiding this comment

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

Hmm, I'm not sure the current solution is the way to go about this, see inline comment.

But even if that inline comment was fixed, I'm not even sure we'd need an option, we should never allow * in the domain (I haven't checked the RFC but pretty sure it's not allowed). E.g. GitHub also doesn't linkify those kinds of URLs, see here: https://*.example.org (but it allows https://a*.example.org)

I feel like this is another one of those cases where it would be good to have stricter parsing of domains, as it would also address some other issues, e.g. #28 (comment).

I think I don't want to accept this in the current state, I'd rather clean up domain parsing which should hopefully make this change unnecessary.

@@ -162,6 +164,11 @@ impl UrlScanner {
// These may be part of an URL but not at the end. It's not that the spec
// doesn't allow them, but they are frequently used in plain text as delimiters
// where they're not meant to be part of the URL.
if !extract_wildcard_urls {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is the right place to add this. If using .wildcards(false) and the text https://example.org/foo.bar, it would only extract https://example.org/foo.

@mre
Copy link
Contributor Author

mre commented May 16, 2022

I think I don't want to accept this in the current state, I'd rather clean up domain parsing which should hopefully make this change unnecessary.

Sure, no worries. Gonna close this PR for now. Would be glad if you could look into the domain parsing if you find some time. 👍

@mre mre closed this May 16, 2022
@mre mre deleted the wildcard_urls branch May 30, 2022 14:36
robinst added a commit that referenced this pull request Jun 27, 2022
Came up in a couple of places: #41, #29, #38, #28. Hopefully we can fix
all of these with these changes.

Not done yet, still want to have domain checking for URLs with certain
schemes (https) but allow everything for others.

If we do that, we may be able to unify the email and plain domain
parsing with the scheme one too.
@robinst
Copy link
Owner

robinst commented Jul 11, 2022

With the changes in 0.9.0, this is no longer a problem: https://github.com/robinst/linkify/blob/main/CHANGELOG.md#090---2022-07-11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Are wildcard operators allowed in links?
2 participants