Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

fix unicode character decoding in json strings #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lualibs-util-jsn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local rparent = P("]")
local comma = P(",")
local colon = P(":")
local dquote = P('"')
local hexdigit = S("0123456789abcdefABCDEF")

local whitespace = lpeg.patterns.whitespace
local optionalws = whitespace^0
Expand All @@ -52,7 +53,8 @@ local escapes = {
["t"] = "\t",
}

local escape_un = C(P("\\u") / "0x" * S("09","AF","af")) / function(s) return utfchar(tonumber(s)) end
local escape_un = Cs(P"\\u" / "0x" * hexdigit * 3) / function(s) return utfchar(tonumber(s)) end

local escape_bs = P([[\]]) / "" * (P(1) / escapes) -- if not found then P(1) is returned i.e. the to be escaped char

local jstring = dquote * Cs((escape_un + escape_bs + (1-dquote))^0) * dquote
Expand Down