Skip to content

Commit

Permalink
Merge pull request #8933 from ckeditor/i/8881-autolink-regexp
Browse files Browse the repository at this point in the history
Fix (link): IP addresses should be converted into links while typing by the Autolink feature. Closes #8881.
  • Loading branch information
oleq authored Feb 2, 2021
2 parents 385234a + c98e2ee commit 5b85b86
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div id="snippet-autolink">
<p>Press <i>Space</i> after a link to see the magic of autolinking: https://ckeditor.com/</p>
<p>This feature also works with e-mail addresses: [email protected]</p>
<p>and IP addresses: http://172.217.18.110</p>
<p>You can use <i>Enter</i> or <i>Shift+Enter</i> to achieve the same result: https://ckeditor.com/</p>
</div>
19 changes: 15 additions & 4 deletions packages/ckeditor5-link/src/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,21 @@ const URL_REG_EXP = new RegExp(
// BasicAuth using user:pass (optional)
'(?:\\S+(?::\\S*)?@)?' +
'(?:' +
// Host & domain names.
'(?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+' +
// TLD identifier name.
'(?:[a-z\\u00a1-\\uffff]{2,})' +
// IP address dotted notation octets
// excludes loopback network 0.0.0.0
// excludes reserved space >= 224.0.0.0
// excludes network & broadcast addresses
// (first & last IP address of each class)
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
'|' +
'(' +
// Host & domain names.
'(?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+' +
// TLD identifier name.
'(?:[a-z\\u00a1-\\uffff]{2,})' +
')' +
')' +
// port number (optional)
'(?::\\d{2,5})?' +
Expand Down
9 changes: 7 additions & 2 deletions packages/ckeditor5-link/tests/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ describe( 'AutoLink', () => {
'http://例子.测试',
'http://उदाहरण.परीक्षा',
'http://1337.net',
'http://a.b-c.de'
'http://a.b-c.de',
'http://127.0.0.1:8080/ckeditor5/latest/features/link.html',
'http://192.168.43.58/ckeditor5/latest/features/link.html',
'http://83.127.13.40',
'http://[email protected]'
];

for ( const supportedURL of supportedURLs ) {
Expand Down Expand Up @@ -311,7 +315,8 @@ describe( 'AutoLink', () => {
'http://localhost',
'http:/cksource.com',
'cksource.com',
'ww.cksource.com'
'ww.cksource.com',
'www.cksource'
];

for ( const unsupportedURL of unsupportedOrInvalid ) {
Expand Down

0 comments on commit 5b85b86

Please sign in to comment.