1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
https://github.com/harningt/luajson/issues/47
https://github.com/harningt/luajson/pull/48
https://github.com/harningt/luajson/pull/49
From 473d61d262a1c86a69ad9b4882352d122e42f3fa Mon Sep 17 00:00:00 2001
From: Josh <jokajak@gmail.com>
Date: Thu, 20 Jul 2023 15:49:33 -0400
Subject: [PATCH] feat: support lpeg 1.1
This changeset adds support for lpeg 1.1 which updated the lpeg.version from a function to a string.
Therefore we have to check the type of the value.
Refs: #47
---
lua/json/decode/util.lua | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lua/json/decode/util.lua b/lua/json/decode/util.lua
index 2493bf3..8b23751 100644
--- a/lua/json/decode/util.lua
+++ b/lua/json/decode/util.lua
@@ -17,6 +17,8 @@ local table_concat = require("table").concat
local merge = require("json.util").merge
+local type = type
+
local _ENV = nil
local function get_invalid_character_info(input, index)
@@ -94,7 +96,8 @@ local unicode_ignored = (unicode_space + comment)^0
-- Parse the lpeg version skipping patch-values
-- LPEG <= 0.7 have no version value... so 0.7 is value
-local DecimalLpegVersion = lpeg.version and tonumber(lpeg.version():match("^(%d+%.%d+)")) or 0.7
+-- LPEG >= 1.1 uses a string for the version instead of function
+local DecimalLpegVersion = lpeg.version and tonumber((type(lpeg.version) == "string" and lpeg.version or lpeg.version()):match("^(%d+%.%d+)")) or 0.7
local function setObjectKeyForceNumber(t, key, value)
key = tonumber(key) or key
From f23e38fc35cea8db78df124f1bd6d3d56e6c9ab1 Mon Sep 17 00:00:00 2001
From: Josh <jokajak@gmail.com>
Date: Wed, 4 Oct 2023 17:24:30 -0400
Subject: [PATCH] fix: fix lpeg version detection
This changeset fixes the lpeg version detection to properly handle
version > 1.1.
The original fix did not properly parse the string because it search for
the number to start the string instead of being part of the string.
Refs: #47
---
lua/json/decode/util.lua | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lua/json/decode/util.lua b/lua/json/decode/util.lua
index 8b23751..4815650 100644
--- a/lua/json/decode/util.lua
+++ b/lua/json/decode/util.lua
@@ -97,7 +97,11 @@ local unicode_ignored = (unicode_space + comment)^0
-- Parse the lpeg version skipping patch-values
-- LPEG <= 0.7 have no version value... so 0.7 is value
-- LPEG >= 1.1 uses a string for the version instead of function
-local DecimalLpegVersion = lpeg.version and tonumber((type(lpeg.version) == "string" and lpeg.version or lpeg.version()):match("^(%d+%.%d+)")) or 0.7
+local DecimalLpegVersion = lpeg.version
+ and tonumber(
+ (type(lpeg.version) == "string" and lpeg.version or lpeg.version()):match("(%d+%.%d+)")
+ )
+ or 0.7
local function setObjectKeyForceNumber(t, key, value)
key = tonumber(key) or key
|