Skip to content

Commit

Permalink
After CR
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Jan 13, 2025
1 parent bcb6315 commit 682cd4a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/bundle/Resources/public/js/CKEditor/helpers/url-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const getSplitedUrl = (url) => {
const splitedUrl = url.split('?');

return {
baseUrl: splitedUrl[0],
queryString: splitedUrl[1],
};
};

const decodeUrlQuery = (url) => {
const { baseUrl, queryString } = getSplitedUrl(url);

if (!queryString) {
return url;
}

return `${baseUrl}?${decodeURI(queryString)}`;
};

const encodeUrlQuery = (url) => {
const { baseUrl, queryString } = getSplitedUrl(url);

if (!queryString) {
return url;
}

return `${baseUrl}?${encodeURI(queryString)}`;
};

export { decodeUrlQuery, encodeUrlQuery };
3 changes: 2 additions & 1 deletion src/bundle/Resources/public/js/CKEditor/link/link-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import findAttributeRange from '@ckeditor/ckeditor5-typing/src/utils/findattribu
import IbexaLinkFormView from './ui/link-form-view';
import IbexaButtonView from '../common/button-view/button-view';
import { getCustomAttributesConfig, getCustomClassesConfig } from '../custom-attributes/helpers/config-helper';
import { encodeUrlQuery } from '../helpers/url-helper';

const { Translator } = window;

Expand Down Expand Up @@ -59,7 +60,7 @@ class IbexaLinkUI extends Plugin {

this.isNew = false;

this.editor.execute('insertIbexaLink', { href: encodeURI(url), title, target, ibexaLinkClasses, ibexaLinkAttributes });
this.editor.execute('insertIbexaLink', { href: encodeUrlQuery(url), title, target, ibexaLinkClasses, ibexaLinkAttributes });
this.hideForm();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { addListToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import { createLabeledSwitchButton } from '../../common/switch-button/utils';
import { createLabeledInputNumber } from '../../common/input-number/utils';
import { getCustomAttributesConfig, getCustomClassesConfig } from '../../custom-attributes/helpers/config-helper';

import { decodeUrlQuery } from '../../helpers/url-helper';
class IbexaLinkFormView extends View {
constructor(props) {
super(props);
Expand Down Expand Up @@ -122,7 +122,7 @@ class IbexaLinkFormView extends View {
}

setValues({ url, title, target, ibexaLinkClasses, ibexaLinkAttributes = {} }) {
this.setStringValue(this.urlInputView, decodeURI(url));
this.setStringValue(this.urlInputView, decodeUrlQuery(url));
this.setStringValue(this.titleView, title);

this.targetSwitcherView.fieldView.element.value = !!target;
Expand Down

0 comments on commit 682cd4a

Please sign in to comment.