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

Support IP & IP:PORT hostnames in URL pattern #46

Closed
webraptor opened this issue Mar 19, 2018 · 2 comments
Closed

Support IP & IP:PORT hostnames in URL pattern #46

webraptor opened this issue Mar 19, 2018 · 2 comments

Comments

@webraptor
Copy link

webraptor commented Mar 19, 2018

Currently the URL pattern doesn't match IP and IP:PORT hostnames.
It supports only FQDN because the regex requires the TLD to be present.

Current regex
/(https?://|www.)[-a-zA-Z0-9@:%.+~#=]{2,256}.[a-z]{2,6}\b([-a-zA-Z0-9@:%+.~#?&//=]*)/i

Proposed regex
/(https?://|www.)[-a-zA-Z0-9@:%.+~#=]{2,256}(.[a-z]{2,6})?\b([-a-zA-Z0-9@:%+.~#?&//=]*)/i
if not very clear by bolding, .[a-z]{2,6} became (.[a-z]{2,6})?

Ideally the URL pattern should be according to RFC 3986 or the newer version RFC 7595

@fbartho fbartho changed the title Improving URL pattern Support IP & IP:PORT hostnames in Improving URL pattern Nov 15, 2018
@fbartho fbartho changed the title Support IP & IP:PORT hostnames in Improving URL pattern Support IP & IP:PORT hostnames in URL pattern Nov 15, 2018
@fbartho
Copy link
Contributor

fbartho commented Nov 15, 2018

@webraptor
I worry that this would start matching undesirable things as so many chunks are optional.

If you want to submit a PR we could potentially see what it looks like & add tests.

Alternatively, obviously, you can override the regexp yourself for some components, or you can in the next release directly patch the PATTERNS table, if you want to apply this fix globally for yourself.

export const PATTERNS = {
url: /(https?:\/\/|www\.)[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*[-a-zA-Z0-9@:%_\+~#?&\/=])*/i,
phone: /[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,7}/,
email: /\S+@\S+\.\S+/,
};

@fbartho
Copy link
Contributor

fbartho commented Jun 11, 2020

I'm going to close this ticket as I provided workarounds 2 years ago! (time flies)

If this is still interesting, we can reopen the ticket.

If you find a bug or have a PR, I'm working on a new release in #79

@fbartho fbartho closed this as completed Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants