From 80e99dfd26298ae2f6a4884ee639dc7a892f7fc6 Mon Sep 17 00:00:00 2001 From: GregorMatheis <33435801+GregorMatheis@users.noreply.github.com> Date: Mon, 8 Mar 2021 09:11:36 +0100 Subject: [PATCH 1/2] Added try/catch into unescapeuri() In the current version unescapeuri() gives an error if the %... character is an invalid base 16. However some url parameters can have %... as part of their value. For those cases the function now gives a warning but returns the string without changes and doesn't throw an error. --- src/URIs.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/URIs.jl b/src/URIs.jl index 6b3e476..859b4ee 100644 --- a/src/URIs.jl +++ b/src/URIs.jl @@ -358,7 +358,7 @@ function unescapeuri(str) if c == '%' c1 = read(io, Char) c = read(io, Char) - write(out, parse(UInt8, string(c1, c); base=16)) + write(out, try parse(UInt8, string(c1, c); base=16) catch e; @warn e; string(c1, c) end) else write(out, c) end From 05e2ba59db2ace5b13ceaea542de2879e78d1dd3 Mon Sep 17 00:00:00 2001 From: GregorMatheis <33435801+GregorMatheis@users.noreply.github.com> Date: Tue, 11 May 2021 11:25:28 +0200 Subject: [PATCH 2/2] Update URIs.jl As mentioned in discussion --- src/URIs.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/URIs.jl b/src/URIs.jl index 859b4ee..bec4dd4 100644 --- a/src/URIs.jl +++ b/src/URIs.jl @@ -348,17 +348,21 @@ decodeplus(q) = replace(q, '+' => ' ') Percent-decode a string according to the URI escaping rules. """ -function unescapeuri(str) +function unescapeuri(str::String; malformatted_error = true) occursin("%", str) || return str out = IOBuffer() i = 1 io = IOBuffer(str) - while !eof(io) + while !eof(io) c = read(io, Char) - if c == '%' + if (c == '%') & malformatted_error c1 = read(io, Char) c = read(io, Char) - write(out, try parse(UInt8, string(c1, c); base=16) catch e; @warn e; string(c1, c) end) + write(out, parse(UInt8, string(c1, c); base=16)) + elseif (!malformatted_error) & (c == '%') & !eof(io) + c1 = read(io, Char) + c = read(io, Char) + write(out, try parse(UInt8, string(c1, c); base=16) catch; string(c1, c) end) else write(out, c) end