Skip to content

Commit

Permalink
[BUGFIX] Correct link parsing with anchor and params
Browse files Browse the repository at this point in the history
Adds parsing of link to ensure correct order of query params and anchor.

Resolves: #88095
Releases: master, 9.5
Change-Id: Ic0bb13ca3f5664e514fe523d96a0bd017fab6b8d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60409
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
andreaskienast committed Nov 29, 2019
1 parent d794b18 commit ab01fab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RteLinkBrowser {
public finalizeFunction(link: string): void {
const linkElement = this.CKEditor.document.createElement('a');
const attributes = LinkBrowser.getLinkAttributeValues();
const params = attributes.params ? attributes.params : '';
let params = attributes.params ? attributes.params : '';

if (attributes.target) {
linkElement.setAttribute('target', attributes.target);
Expand All @@ -91,7 +91,24 @@ class RteLinkBrowser {
linkElement.setAttribute(attrName, attrValue);
});

linkElement.setAttribute('href', link + params);
// Make sure, parameters and anchor are in correct order
const linkMatch = link.match(/^([a-z0-9]+:\/\/[^:\/?#]+(?:\/?[^?#]*)?)(\??[^#]*)(#?.*)$/)
if (linkMatch && linkMatch.length > 0) {
link = linkMatch[1] + linkMatch[2];
const paramsPrefix = linkMatch[2].length > 0 ? '&' : '?';
if (params.length > 0) {
if (params[0] === '&') {
params = params.substr(1)
}
// If params is set, append it
if (params.length > 0) {
link += paramsPrefix + params;
}
}
link += linkMatch[3];
}

linkElement.setAttribute('href', link);

const selection = this.CKEditor.getSelection();
if (selection && selection.getSelectedText() === '') {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab01fab

Please sign in to comment.