Skip to content

Commit

Permalink
Fix double escaping of '&' (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimikage authored Mar 18, 2024
1 parent 1e5208b commit 99b73f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/svgwriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<' => "&lt;")
s = replace(str, '&' => "&amp;") # '&' must be first
s = replace(s, '\'' => "&apos;")
s = replace(s, '"' => "&quot;")
s = replace(s, '>' => "&gt;")
s = replace(s, '&' => "&amp;")
s = replace(s, '<' => "&lt;")
s
end

Expand Down
11 changes: 2 additions & 9 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@
return text.slice(0, nchars - 2) + '..';
};

var unescapeHtml = function (str) {
return str
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&');
};

var isDarkColor = function (c) {
var m = c.match(/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/);
if (m) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -347,6 +347,7 @@ end
show(io, "text/html", fg)
str = String(take!(io))
@test occursin(r"<html>.+(?=</html>)"s, str)
@test occursin(">&gt; in file1:20</text>", str)
end

@testset "set_default" begin
Expand Down

0 comments on commit 99b73f7

Please sign in to comment.