From 0cbd6c3636c96ef95ca247bb6eeb448268901ad4 Mon Sep 17 00:00:00 2001 From: KyleN <25726366+kyl3n@users.noreply.github.com> Date: Fri, 26 Jul 2019 19:51:39 -0600 Subject: [PATCH 1/2] Fixed locale floating point character When running this code in locales that do not use a period for floating point integers, an error would occur. This is now resolved. --- json.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/json.lua b/json.lua index 098e7b2..4e4b71a 100644 --- a/json.lua +++ b/json.lua @@ -154,6 +154,8 @@ local space_chars = create_set(" ", "\t", "\r", "\n") local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",") local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u") local literals = create_set("true", "false", "null") +local locale_character = (string.match(tostring(tonumber(1.1)),'%p')) -- return the locale punctuation character according to the locale + local literal_map = { [ "true" ] = true, @@ -271,6 +273,7 @@ end local function parse_number(str, i) local x = next_char(str, i, delim_chars) local s = str:sub(i, x - 1) + s = s:gsub('%p',locale_character) -- replace the locale punctuation character in the string with the correct one local n = tonumber(s) if not n then decode_error(str, i, "invalid number '" .. s .. "'") From a8d5dc7e9d7069192ae2ff86d5beed0b6b0bba39 Mon Sep 17 00:00:00 2001 From: KyleN <25726366+kyl3n@users.noreply.github.com> Date: Mon, 26 Aug 2019 14:17:03 -0600 Subject: [PATCH 2/2] replace only comma or decimal in floating point integer previous version was replacing minus sign in negative numbers in error. --- json.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/json.lua b/json.lua index 4e4b71a..e0513e6 100644 --- a/json.lua +++ b/json.lua @@ -154,7 +154,7 @@ local space_chars = create_set(" ", "\t", "\r", "\n") local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",") local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u") local literals = create_set("true", "false", "null") -local locale_character = (string.match(tostring(tonumber(1.1)),'%p')) -- return the locale punctuation character according to the locale +local locale_character = (string.match(tostring(1/2),'%p')) -- return point decimal or comma decimal according to the locale local literal_map = { @@ -273,15 +273,13 @@ end local function parse_number(str, i) local x = next_char(str, i, delim_chars) local s = str:sub(i, x - 1) - s = s:gsub('%p',locale_character) -- replace the locale punctuation character in the string with the correct one + s = s:gsub('[%.%,]',locale_character) -- replace the comma decimal or point decimal with the correct one according to the locale local n = tonumber(s) if not n then decode_error(str, i, "invalid number '" .. s .. "'") end return n, x end - - local function parse_literal(str, i) local x = next_char(str, i, delim_chars) local word = str:sub(i, x - 1)