From 818ad1534a3c1632a670319f4d68db9bc8db3509 Mon Sep 17 00:00:00 2001 From: kimikage Date: Tue, 19 Mar 2024 04:33:42 +0900 Subject: [PATCH] Fix double escaping of '&' --- src/svgwriter.jl | 6 ++++-- src/viewer.js | 11 ++--------- test/runtests.jl | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/svgwriter.jl b/src/svgwriter.jl index d54bb89..3b54ad8 100644 --- a/src/svgwriter.jl +++ b/src/svgwriter.jl @@ -2,9 +2,11 @@ const snapsvgjs = joinpath(@__DIR__, "..", "deps", "snap.svg-min.js") const viewerjs = joinpath(@__DIR__, "viewer.js") function escape_html(str::AbstractString) - s = replace(str, '<' => "<") + s = replace(str, '&' => "&") # '&' must be first + s = replace(s, '\'' => "'") + s = replace(s, '"' => """) s = replace(s, '>' => ">") - s = replace(s, '&' => "&") + s = replace(s, '<' => "<") s end diff --git a/src/viewer.js b/src/viewer.js index 0fc25b7..664926a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -65,13 +65,6 @@ return text.slice(0, nchars - 2) + '..'; }; - var unescapeHtml = function (str) { - return str - .replace(/</g, '<') - .replace(/>/g, '>') - .replace(/&/g, '&'); - }; - var isDarkColor = function (c) { var m = c.match(/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/); if (m) { @@ -320,8 +313,8 @@ rects.forEach(function (r) { var rect = r.node; var text = rect.nextElementSibling; - rect.setAttribute('data-shortinfo', unescapeHtml(text.textContent)); - var dir = unescapeHtml(rect.getAttribute('data-dinfo')); + rect.setAttribute('data-shortinfo', text.textContent); + var dir = rect.getAttribute('data-dinfo'); rect.setAttribute('data-dinfo', dir); rect.addEventListener('dblclick', rectDblClickHandler, false); rect.addEventListener('mouseover', rectMouseOverHandler, false); diff --git a/test/runtests.jl b/test/runtests.jl index 661fce8..8f8c692 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,7 +22,7 @@ lidict = Dict{UInt64,StackFrame}(1=>stackframe(:f1, :file1, 1), 2=>stackframe(:jl_f, :filec, 55; C=true), 3=>stackframe(:jl_invoke, :file2, 1; C=true), 4=>stackframe(:_ZL, Symbol("libLLVM-8.0.so"), 15), - 5=>stackframe(:f4, :file1, 20), + 5=>stackframe(Symbol(">"), :file1, 20), 6=>stackframe(:copy, Symbol(".\\expr.jl"), 1), 7=>stackframe(:f1, :file1, 2), 8=>stackframe(:typeinf, Symbol("./compiler/typeinfer.jl"), 10)) @@ -347,6 +347,7 @@ end show(io, "text/html", fg) str = String(take!(io)) @test occursin(r".+(?=)"s, str) + @test occursin(">> in file1:20", str) end @testset "set_default" begin