Skip to content

Commit

Permalink
Merge pull request #9070 from ckeditor/i/8050
Browse files Browse the repository at this point in the history
Fix (link): Autolink will no longer automatically match domains that only have a `www` subdomain followed with a top level domain, e.g. `http://www.test`. Closes #8050.
  • Loading branch information
mlewand committed Feb 23, 2021
2 parents 87ad794 + 44cbbb2 commit 2165447
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/ckeditor5-link/src/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const URL_REG_EXP = new RegExp(
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
'|' +
'(' +
// Do not allow `www.foo` - see https://github.com/ckeditor/ckeditor5/issues/8050.
'((?!www\\.)|(www\\.))' +
// Host & domain names.
'(?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+' +
// TLD identifier name.
Expand All @@ -54,9 +56,9 @@ const URL_REG_EXP = new RegExp(
'(www.|(\\S+@))' +
// Host & domain names.
'((?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.))+' +
// TLD identifier name.
'(?:[a-z\\u00a1-\\uffff]{2,})' +
')' +
// TLD identifier name.
'(?:[a-z\\u00a1-\\uffff]{2,})' +
')' +
')$', 'i' );

const URL_GROUP_IN_MATCH = 2;
Expand Down
19 changes: 17 additions & 2 deletions packages/ckeditor5-link/tests/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,25 @@ describe( 'AutoLink', () => {
);
} );

it( 'adds linkHref attribute on enter when the link (that contains www) is partially selected (end)', () => {
it( 'adds linkHref attribute on enter when the link (containing www) is partially selected (end)' +
'and the remaining fragment is a proper URL', () => {
setData( model, '<paragraph>https://www.foo.ba[r.com]</paragraph>' );

editor.execute( 'enter' );

expect( getData( model ) ).to.equal(
'<paragraph><$text linkHref="https://www.foo.ba">https://www.foo.ba</$text></paragraph><paragraph>[]</paragraph>'
);
} );

it( 'does not add a linkHref attribute for links with www subdomain only, pressing enter with part of its end selected', () => {
// https://github.com/ckeditor/ckeditor5/issues/8050.
setData( model, '<paragraph>https://www.ckso[urce.com]</paragraph>' );

editor.execute( 'enter' );

expect( getData( model ) ).to.equal(
'<paragraph><$text linkHref="https://www.ckso">https://www.ckso</$text></paragraph><paragraph>[]</paragraph>'
'<paragraph>https://www.ckso</paragraph><paragraph>[]</paragraph>'
);
} );

Expand Down Expand Up @@ -265,6 +277,8 @@ describe( 'AutoLink', () => {
'http://🥳.cksource.com/',
'http://code.cksource.com/woot/#&product=browser',
'http://j.mp',
'http://ww.mp',
'http://wwww.mp',
'ftp://cksource.com/baz',
'http://cksource.com/?q=Test%20URL-encoded%20stuff',
'http://مثال.إختبار',
Expand Down Expand Up @@ -314,6 +328,7 @@ describe( 'AutoLink', () => {
'http://-error-.invalid/',
'http://localhost',
'http:/cksource.com',
'http://www.cksource', // https://github.com/ckeditor/ckeditor5/issues/8050.
'cksource.com',
'ww.cksource.com',
'www.cksource'
Expand Down

0 comments on commit 2165447

Please sign in to comment.