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

Problem with single character domains (looseUrlRegex) (a.co) #115

Open
felixwortmann opened this issue Nov 29, 2022 · 0 comments
Open

Problem with single character domains (looseUrlRegex) (a.co) #115

felixwortmann opened this issue Nov 29, 2022 · 0 comments

Comments

@felixwortmann
Copy link

Single character domains do not work properly in the current version (5.0.2) because the regex does not support it

I encountered some problems with shortened amazon links (https://a.co). These do not work with looseUrlRegex. Below is some code to reproduce the issue (the regex are taken directly from the library code):

Code

final _looseUrlRegex = RegExp(r'^(.*?)((https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))',
  caseSensitive: false,
  dotAll: true,
);
final _urlRegex = RegExp(r'^(.*?)((?:https?:\/\/|www\.)[^\s/$.?#].[^\s]*)',
  caseSensitive: false,
  dotAll: true,
);
print('match loose without https: ${_looseUrlRegex.firstMatch("a.co")?.group(0)}');
print('match regular without https: ${_urlRegex.firstMatch("a.co")?.group(0)}');
print('match loose with https: ${_looseUrlRegex.firstMatch("https://a.co")?.group(0)}');
print('match regular with https: ${_urlRegex.firstMatch("https://a.co")?.group(0)}');

Output

match loose without https: null // this should have a match
match regular without https: null
match loose with https: null // this should have a match
match regular with https: https://a.co
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

No branches or pull requests

1 participant