From a7a07425e39bf450d7c56765374080f2c160ecce Mon Sep 17 00:00:00 2001 From: Julian Dehm Date: Mon, 22 Jan 2024 11:36:36 +0100 Subject: [PATCH] improve handling of config values containing slashes Use a regexp to test if a value might be a valid regexp. This fixes config values ending up broken if they contain slashes but are not actually a regexp. One such example is: "link": {"defaultProtocol": "https://"} --- django_ckeditor_5/static/django_ckeditor_5/app.js | 6 ++++-- example/blog/blog/settings.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django_ckeditor_5/static/django_ckeditor_5/app.js b/django_ckeditor_5/static/django_ckeditor_5/app.js index 7df6bfa..8bee2f8 100644 --- a/django_ckeditor_5/static/django_ckeditor_5/app.js +++ b/django_ckeditor_5/static/django_ckeditor_5/app.js @@ -44,8 +44,10 @@ function createEditors() { const config = JSON.parse( document.getElementById(`${script_id}-span`).textContent, (key, value) => { - if (value.toString().includes('/')) { - return new RegExp(value.replaceAll('/', '')); + var match = value.toString().match(new RegExp('^/(.*?)/([gimy]*)$')); + if (match) { + var regex = new RegExp(match[1], match[2]); + return regex; } return value; } diff --git a/example/blog/blog/settings.py b/example/blog/blog/settings.py index bccec4f..4bc7a36 100644 --- a/example/blog/blog/settings.py +++ b/example/blog/blog/settings.py @@ -281,6 +281,7 @@ "reversed": True, }, }, + "link": {"defaultProtocol": "https://"}, "htmlSupport": { "allow": [ {"name": "/.*/", "attributes": True, "classes": True, "styles": True},