|
From: Александр М. <ale...@li...> - 2026-02-17 11:47:36
|
Dear all, sorry for submitting a patch in an irregular way, but I was unable to login to SourceForge: the CloudFlare security check loops infinitely. The patch refers to the bug I was able to file anonymously: https://sourceforge.net/p/gnuplot/bugs/2858/. I will reproduce its text here: If an SVG file with "mouse" is created, embedded into a web page and then opened in a browser, parseSettings() in gnuplot_svg() in gnuplot_svg.js tries to convert the commented JavaScript with statements like gnuplot_svg.setting = (value); into JSON. However, the comment fragment contains more newlines than expected and, after all regexes are applied, has double commas, commas in the beginning and commas in the end; causing JSON.parse() to fail, breaking all the subsequent JavaScript. I would like to submit a patch fixing this, and for this purpose am creating this bug. The proposed patch replaces the attempts to parse JavaScript with regular expressions with eval(), wrepped, inside and outside, with anonymous functions. I and enclosing the short patch, and copying it below, in case this mailing list does not process attachments: diff --git a/term/js/gnuplot_svg.js b/term/js/gnuplot_svg.js index 3d5541dd3..002b3a2ae 100644 --- a/term/js/gnuplot_svg.js +++ b/term/js/gnuplot_svg.js @@ -93,18 +93,7 @@ gnuplot_svg = function (svgElement) { // continous sections witch will lead to failure if we dont // combine them back into 1 var scriptText = script[1].innerHTML.replaceAll("<![CDATA[", "").replaceAll("]]>", "") - // Remove inline comments - scriptText = scriptText.replace(/^\s*\/\/.*\n/g, ''); - // Change prefix to " - scriptText = scriptText.replace(/gnuplot_svg\./g, '"'); - // Change = to " : - scriptText = scriptText.replace(/ = /g, '" : '); - // Change line endings to comma - scriptText = scriptText.replace(/;\n|\n/g, ','); - // Remove last comma - scriptText = scriptText.replace(/,+$/, ''); - // Parse as json string - settings = JSON.parse("{\n" + scriptText + "\n}"); + settings = ( () => eval( '( () => { let gnuplot_svg = {}; ' + scriptText + ' return gnuplot_svg; } )();' ) )(); } }; -- Alexander Mashin |