Skip to content

Commit

Permalink
EZP-31371: Copying a web page link w/o protocol in a Word paragraph l…
Browse files Browse the repository at this point in the history
…eads to a 404 error (#1245)

* EZP-31371: Copying a web page link w/o protocol in a Word paragraph leads to a 404 error

* changed event to CKEditor's afterPaste
  • Loading branch information
konradoboza authored Feb 19, 2020
1 parent cfc9e9d commit e41d98f
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
nativeEditor.on('change', saveRichText);
nativeEditor.on('customUpdate', saveRichText);
nativeEditor.on('editorInteraction', saveRichText);
nativeEditor.on('afterPaste', () => {
this.setLinksProtocol(container);
});

return alloyEditor;
}
Expand Down Expand Up @@ -390,6 +393,24 @@
splitIntoWords(text) {
return text.split(' ').filter((word) => word.trim());
}

setLinksProtocol(container) {
const links = container.querySelectorAll('a');
const anchorPrefix = '#';
const protocolPrefix = 'http://';

links.forEach((link) => {
const href = link.getAttribute('href');
const protocolPattern = /^https?:\/\//i;

if (href && href.indexOf(anchorPrefix) !== 0 && !protocolPattern.test(href)) {
const protocolHref = protocolPrefix.concat(href);

link.setAttribute('href', protocolHref);
link.setAttribute('data-cke-saved-href', protocolHref);
}
});
}
};

eZ.BaseRichText = BaseRichText;
Expand Down

0 comments on commit e41d98f

Please sign in to comment.