Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/core/link.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(function() {
'use strict';

var REGEX_BOOKMARK_SCHEME = /^#.*/i;
var REGEX_EMAIL_SCHEME = /^[a-z0-9\u0430-\u044F\._-]+@/i;
var REGEX_URI_SCHEME = /^(?:[a-z][a-z0-9+\-.]*)\:|^\//i;

Expand Down Expand Up @@ -214,8 +215,9 @@
},

/**
* Checks if the URI has an '@' symbol. If it does and the URI looks like an email
* and doesn't have 'mailto:', 'mailto:' is added to the URI.
* Checks if the URI begins with a '#' symbol to determine if it's an on page bookmark.
* If it doesn't, it then checks if the URI has an '@' symbol. If it does and the URI
* looks like an email and doesn't have 'mailto:', 'mailto:' is added to the URI.
* If it doesn't and the URI doesn't have a scheme, the default 'http' scheme with
* hierarchical path '//' is added to the URI.
*
Expand All @@ -227,7 +229,9 @@
* @return {String} The URI updated with the protocol.
*/
_getCompleteURI: function(URI) {
if (REGEX_EMAIL_SCHEME.test(URI)) {
if (REGEX_BOOKMARK_SCHEME.test(URI)) {
return URI;
} else if (REGEX_EMAIL_SCHEME.test(URI)) {
URI = 'mailto:' + URI;
} else if (!REGEX_URI_SCHEME.test(URI)) {
URI = this.appendProtocol ? 'http://' + URI : URI;
Expand Down
17 changes: 17 additions & 0 deletions test/core/test/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@
assert.strictEqual(data, '<p>set a <a href="//test.com" target="_blank">selection</a> and then convert it to a link.</p>');
});

it('should not add default protocol if link is an on page bookmark', function() {
var link = new CKEDITOR.Link(this.nativeEditor);

bender.tools.selection.setWithHtml(this.nativeEditor, 'set a {selection} and then convert it to a link.');

link.create('#bookmark', {
target: '_blank'
});

var data = bender.tools.getData(this.nativeEditor, {
fixHtml: true,
compatHtml: true
});

assert.strictEqual(data, '<p>set a <a href="#bookmark" target="_blank">selection</a> and then convert it to a link.</p>');
});

it('should add mailto: when creating an email link', function() {
var link = new CKEDITOR.Link(this.nativeEditor);

Expand Down