Skip to content

Commit

Permalink
Make linkValidation allow hash links
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Croney committed Jul 13, 2016
1 parent d57e4b2 commit a357a67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions spec/anchor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,24 @@ describe('Anchor Button TestCase', function () {
expect(link).not.toBeNull();
expect(link.href).toBe(validUrl.toLowerCase());
});
it('should not change fragment identifier when link begins with hash', function () {
var editor = this.newMediumEditor('.editor', {
anchor: {
linkValidation: true
}
}),
validHashLink = '#!$&\'()*+,;=123abcDEF-._~:@/?',
link,
anchorExtension = editor.getExtensionByName('anchor');

selectElementContentsAndFire(editor.elements[0]);
anchorExtension.showForm(validHashLink);
fireEvent(anchorExtension.getForm().querySelector('a.medium-editor-toolbar-save'), 'click');

link = editor.elements[0].querySelector('a');
expect(link).not.toBeNull();
expect(link.getAttribute('href')).toBe(validHashLink);
});
it('should change spaces to %20 for a valid url if linkValidation options is set to true', function () {
var editor = this.newMediumEditor('.editor', {
anchor: {
Expand Down
3 changes: 2 additions & 1 deletion src/js/extensions/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
// Matches any alphabetical characters followed by ://
// Matches protocol relative "//"
// Matches common external protocols "mailto:" "tel:" "maps:"
var urlSchemeRegex = /^([a-z]+:)?\/\/|^(mailto|tel|maps):/i,
// Matches relative hash link, "#" followed by any character
var urlSchemeRegex = /^([a-z]+:)?\/\/|^(mailto|tel|maps):|^\#.+/i,
// var te is a regex for checking if the string is a telephone number
telRegex = /^\+?\s?\(?(?:\d\s?\-?\)?){3,20}$/;
if (telRegex.test(value)) {
Expand Down

0 comments on commit a357a67

Please sign in to comment.