52 lines
2.1 KiB
Diff
52 lines
2.1 KiB
Diff
From 4198da3854ccfaabcb85de23fa4cf8144e45b44d Mon Sep 17 00:00:00 2001
|
|
From: Thomas Harning Jr <harningt@gmail.com>
|
|
Date: Mon, 18 Apr 2016 23:12:33 -0400
|
|
Subject: [PATCH 52/66] decode.strings+tests: fixes additionalEscapes to
|
|
override builtin escapes and side-step escapeCheck needing to be altered
|
|
|
|
---
|
|
lua/json/decode/strings.lua | 6 +++---
|
|
tests/lunit-tests.lua | 6 ++++--
|
|
2 files changed, 7 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/lua/json/decode/strings.lua b/lua/json/decode/strings.lua
|
|
index cb3b5cc..4272f29 100644
|
|
--- a/lua/json/decode/strings.lua
|
|
+++ b/lua/json/decode/strings.lua
|
|
@@ -107,12 +107,12 @@ local function generateLexer(options)
|
|
local escapeMatch = doSimpleSub
|
|
escapeMatch = escapeMatch + doXSub / decodeX
|
|
escapeMatch = escapeMatch + doUniSub / options.decodeUnicode
|
|
- if options.additionalEscapes then
|
|
- escapeMatch = escapeMatch + options.additionalEscapes
|
|
- end
|
|
if options.escapeCheck then
|
|
escapeMatch = options.escapeCheck * escapeMatch + bad_escape
|
|
end
|
|
+ if options.additionalEscapes then
|
|
+ escapeMatch = options.additionalEscapes + escapeMatch
|
|
+ end
|
|
local captureString
|
|
for i = 1, #quotes do
|
|
local cap = buildCaptureString(quotes[i], options.badChars, escapeMatch)
|
|
diff --git a/tests/lunit-tests.lua b/tests/lunit-tests.lua
|
|
index 10f38cb..d2f183f 100644
|
|
--- a/tests/lunit-tests.lua
|
|
+++ b/tests/lunit-tests.lua
|
|
@@ -44,8 +44,10 @@ function test_preprocess()
|
|
end
|
|
|
|
function test_additionalEscapes_only()
|
|
- -- Need to do escape while skipping escape character san-check
|
|
- assert_equal("Hello", json.decode([["\S"]], { strings = { additionalEscapes = lpeg.C(lpeg.P("S")) / "Hello", escapeCheck= false } }))
|
|
+ -- Test that additionalEscapes is processed on its own - side-stepping normal processing
|
|
+ assert_equal("Hello\\?", json.decode([["\S"]], { strings = { additionalEscapes = lpeg.C(lpeg.P("S")) / "Hello\\?" } }))
|
|
+ -- Test that additionalEscapes overrides any builtin handling
|
|
+ assert_equal("Hello\\?", json.decode([["\n"]], { strings = { additionalEscapes = lpeg.C(lpeg.P("n")) / "Hello\\?" } }))
|
|
end
|
|
|
|
local strictDecoder = json.decode.getDecoder(true)
|
|
--
|
|
2.19.1
|
|
|