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

url plugin bug(TLD problem) #2078

Closed
largeden opened this issue Jul 6, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@largeden
Copy link
Contributor

commented Jul 6, 2017

Steps to reproduce the problem.

test.jpg
test.exe

Froala Version.

2.6.2

The domain link feature does not work correctly because the regular expression in the plugin does not check Domain TLD.

I changed the code by referring to the regular expression below.
https://autohotkey.com/boards/viewtopic.php?t=15269

  $.FE.URLRegEx = '(^| |\\u00A0)((https?:\\/\\/(www\\.)?)?((?:[-a-zA-Z0-9@:%_\\+~#=]{2,256}\.)?(?:[-a-zA-Z0-9@:%_\\+~#=]{2,256}\.)(com|net|jp|kr|co|`domainTLD`)|([\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}([-a-zA-Z0-9@:%_\\+~#?&/=]*))))$';

Also, it seems better to remove $.FE.KEYCODE.PERIOD from the key event.
Please check. :)

@largeden

This comment has been minimized.

Copy link
Contributor Author

commented Jul 6, 2017

This regular expression is not perfect. I'll think a bit more.

@stefanneculai stefanneculai marked this as a duplicate of #2094 Jul 17, 2017

stefanneculai added a commit that referenced this issue Jul 18, 2017

@stefanneculai

This comment has been minimized.

Copy link
Contributor

commented Jul 18, 2017

@largeden last commit should fix it. The regular expression for checking URLS is built differently now and it passes most of the validations from https://mathiasbynens.be/demo/url-regex, except the IPs one which IMO should be let as valid input from user in this case. Also, the RegEx is safe which is a huge plus. It's built like this:

  // Chars to allow.
  var x = 'a-z\\u0080-\\u009f\\u00a1-\\uffff0-9';

  // Common regex to avoid double chars.
  $.FE.LinkRegExCommon = '(([' + x + '])|([' + x + '](\\.|-|_))){1,}[' + x + ']{1,}';

  // PORT:something_else.php
  $.FE.LinkRegExEnd = '((:[0-9]{1,5})|())((\\/[a-z\\u00a1-\\uffff0-9@?^=%&\/~+#-_{}]*)|())';

  // Common TLD
  $.FE.LinkRegExTLD = '((' + $.FE.LinkRegExCommon + ')(\\.(com|net|org|edu|mil|gov|co|biz|info|me|dev)))';

  // Starts with HTTP.
  $.FE.LinkRegExHTTP = '((ftp|http|https):\\/\\/(www\\.)?' + $.FE.LinkRegExCommon + ')';

  // Authenticate with HTTP.
  $.FE.LinkRegExAuth = '((ftp|http|https):\\/\\/(www\\.)?[\\u0021-\\uffff]{1,}@' + $.FE.LinkRegExCommon + ')';

  // Starts with WWWW.
  $.FE.LinkRegExWWW = '(((ftp|http|https):\\/\\/)?www\\.' + $.FE.LinkRegExCommon + '\\.[a-z0-9-]{2,24})';

  // Join.
  $.FE.LinkRegEx =  '(' + $.FE.LinkRegExTLD + '|' + $.FE.LinkRegExHTTP + '|' + $.FE.LinkRegExAuth + '|' + $.FE.LinkRegExWWW + ')' + $.FE.LinkRegExEnd;

PS: More details about that in a blog post shortly.

@largeden

This comment has been minimized.

Copy link
Contributor Author

commented Jul 19, 2017

Thank you!
I am looking forward to the blog post. :p

@largeden

This comment has been minimized.

Copy link
Contributor Author

commented Aug 25, 2017

hi @stefanneculai
This regular still needs a modification.

The following text are also auto linked.

test.comalekjfleafjljf

@stefanneculai stefanneculai reopened this Aug 28, 2017

stefanneculai added a commit that referenced this issue Sep 11, 2017

@largeden

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.