From 4ca959c3637f66245ef64c1c5a17e88364422cc2 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Sun, 17 Jul 2022 14:52:31 +0200 Subject: [PATCH 1/5] [JENKINS-60866] Use JSON#parse to process codemirror-config argument --- core/src/main/java/hudson/markup/MarkupFormatter.java | 11 ++++++++--- .../main/resources/hudson/tasks/Shell/config.groovy | 2 +- core/src/main/resources/lib/form/textarea/textarea.js | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/markup/MarkupFormatter.java b/core/src/main/java/hudson/markup/MarkupFormatter.java index e588e0cfcc8e..5ff0233eb71c 100644 --- a/core/src/main/java/hudson/markup/MarkupFormatter.java +++ b/core/src/main/java/hudson/markup/MarkupFormatter.java @@ -60,9 +60,14 @@ * This is an extension point in Hudson, allowing plugins to implement different markup formatters. * *

- * Implement the following methods to enable and control CodeMirror syntax highlighting - * public String getCodeMirrorMode() // return null to disable CodeMirror dynamically - * public String getCodeMirrorConfig() + * Implement the following methods to enable and control CodeMirror syntax highlighting: + *

* *

Views

*

diff --git a/core/src/main/resources/hudson/tasks/Shell/config.groovy b/core/src/main/resources/hudson/tasks/Shell/config.groovy index f895ffe88f3e..bfd163196917 100644 --- a/core/src/main/resources/hudson/tasks/Shell/config.groovy +++ b/core/src/main/resources/hudson/tasks/Shell/config.groovy @@ -25,7 +25,7 @@ package hudson.tasks.Shell f=namespace(lib.FormTagLib) f.entry(title:_("Command"),description:_("description",rootURL)) { - f.textarea(name: "command", value: instance?.command, class: "fixed-width", 'codemirror-mode': 'shell', 'codemirror-config': "mode: 'text/x-sh'") + f.textarea(name: "command", value: instance?.command, class: "fixed-width", 'codemirror-mode': 'shell', 'codemirror-config': '"mode": "text/x-sh"') } f.advanced() { diff --git a/core/src/main/resources/lib/form/textarea/textarea.js b/core/src/main/resources/lib/form/textarea/textarea.js index eb21c82ee5b0..37b7a9afa17e 100644 --- a/core/src/main/resources/lib/form/textarea/textarea.js +++ b/core/src/main/resources/lib/form/textarea/textarea.js @@ -14,7 +14,11 @@ Behaviour.specify("TEXTAREA.codemirror", 'textarea', 0, function(e) { if (!config) { config = ''; } - config = eval('({'+config+'})'); + try { + config = JSON.parse('{' + config + '}'); + } catch (e) { + console.log("Failed to parse codemirror-config '{" + config + "}' as JSON", e); + } if (!config.onBlur) { config.onBlur = function(editor) { editor.save(); }; } From 12921dfe5bd5300045b893c5390e7962751800da Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Sun, 17 Jul 2022 15:03:37 +0200 Subject: [PATCH 2/5] Add backward compatibility for most common setting --- .../main/resources/lib/form/textarea/textarea.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/form/textarea/textarea.js b/core/src/main/resources/lib/form/textarea/textarea.js index 37b7a9afa17e..90e80bfe090f 100644 --- a/core/src/main/resources/lib/form/textarea/textarea.js +++ b/core/src/main/resources/lib/form/textarea/textarea.js @@ -17,7 +17,18 @@ Behaviour.specify("TEXTAREA.codemirror", 'textarea', 0, function(e) { try { config = JSON.parse('{' + config + '}'); } catch (e) { - console.log("Failed to parse codemirror-config '{" + config + "}' as JSON", e); + /* + Attempt to parse fairly common legacy format whose exact content is: + mode:'' + */ + let match = config.match("^mode: ?'([^']+)'$"); + if (match) { + console.log("Parsing simple legacy codemirror-config value using fallback: " + config); + config = { mode: match[1] }; + } else { + console.log("Failed to parse codemirror-config '{" + config + "}' as JSON", e); + config = {}; + } } if (!config.onBlur) { config.onBlur = function(editor) { editor.save(); }; From 9c238ff0ad2ca9393ae4b92d50294b602da67602 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Sun, 17 Jul 2022 23:01:03 +0200 Subject: [PATCH 3/5] Integrate fixed antisamy-markup-formatter to pass test --- test/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/pom.xml b/test/pom.xml index 5ed65f2e135d..3127d02b271b 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -150,7 +150,8 @@ THE SOFTWARE. org.jenkins-ci.plugins antisamy-markup-formatter - 2.7 + + 137.v29a_a_e8b_c5f12 test From b1964838e8f9894a8f711c12e694631c9036f4ee Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Tue, 30 Aug 2022 13:13:32 +0200 Subject: [PATCH 4/5] Fix JS and revert unnecessary antisamy-markup-formatter update How do we have a billion different linters and not one did tell me I'm redefining a variable? --- core/src/main/resources/lib/form/textarea/textarea.js | 4 ++-- test/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/resources/lib/form/textarea/textarea.js b/core/src/main/resources/lib/form/textarea/textarea.js index 3c69434a0dfc..beb688f714d3 100644 --- a/core/src/main/resources/lib/form/textarea/textarea.js +++ b/core/src/main/resources/lib/form/textarea/textarea.js @@ -16,7 +16,7 @@ Behaviour.specify("TEXTAREA.codemirror", "textarea", 0, function (e) { } try { config = JSON.parse("{" + config + "}"); - } catch (e) { + } catch (ex) { /* * Attempt to parse fairly common legacy format whose exact content is: * mode:'' @@ -31,7 +31,7 @@ Behaviour.specify("TEXTAREA.codemirror", "textarea", 0, function (e) { } else { console.log( "Failed to parse codemirror-config '{" + config + "}' as JSON", - e + ex ); config = {}; } diff --git a/test/pom.xml b/test/pom.xml index c17a2886631c..d207dc80c958 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -151,7 +151,7 @@ THE SOFTWARE. org.jenkins-ci.plugins antisamy-markup-formatter - 137.v29a_a_e8b_c5f12 + 2.7 test From 6b9035096dee73033bf6da63cf67d23e7cc6fc9d Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Tue, 30 Aug 2022 13:16:31 +0200 Subject: [PATCH 5/5] Remove comment --- test/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/pom.xml b/test/pom.xml index d207dc80c958..37e038d6526b 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -150,7 +150,6 @@ THE SOFTWARE. org.jenkins-ci.plugins antisamy-markup-formatter - 2.7 test