From 682cd4afb49be910b1b9d45cd9b8fe4441f411af Mon Sep 17 00:00:00 2001 From: Lukasz Ostafin Date: Fri, 20 Dec 2024 16:14:22 +0100 Subject: [PATCH] After CR --- .../public/js/CKEditor/helpers/url-helper.js | 30 +++++++++++++++++++ .../public/js/CKEditor/link/link-ui.js | 3 +- .../js/CKEditor/link/ui/link-form-view.js | 4 +-- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/bundle/Resources/public/js/CKEditor/helpers/url-helper.js diff --git a/src/bundle/Resources/public/js/CKEditor/helpers/url-helper.js b/src/bundle/Resources/public/js/CKEditor/helpers/url-helper.js new file mode 100644 index 00000000..5b154c9b --- /dev/null +++ b/src/bundle/Resources/public/js/CKEditor/helpers/url-helper.js @@ -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 }; diff --git a/src/bundle/Resources/public/js/CKEditor/link/link-ui.js b/src/bundle/Resources/public/js/CKEditor/link/link-ui.js index 4e304e6a..82d02bda 100644 --- a/src/bundle/Resources/public/js/CKEditor/link/link-ui.js +++ b/src/bundle/Resources/public/js/CKEditor/link/link-ui.js @@ -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; @@ -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(); }); diff --git a/src/bundle/Resources/public/js/CKEditor/link/ui/link-form-view.js b/src/bundle/Resources/public/js/CKEditor/link/ui/link-form-view.js index 4fab6b22..07cd0546 100644 --- a/src/bundle/Resources/public/js/CKEditor/link/ui/link-form-view.js +++ b/src/bundle/Resources/public/js/CKEditor/link/ui/link-form-view.js @@ -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); @@ -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;