diff --git a/src/core/link.js b/src/core/link.js index 1948029281..d085668dcf 100644 --- a/src/core/link.js +++ b/src/core/link.js @@ -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; @@ -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. * @@ -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; diff --git a/test/core/test/link.js b/test/core/test/link.js index 62b611bf6c..c59dc01152 100644 --- a/test/core/test/link.js +++ b/test/core/test/link.js @@ -82,6 +82,23 @@ assert.strictEqual(data, '

set a selection and then convert it to a link.

'); }); + 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, '

set a selection and then convert it to a link.

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