From 100ff882f606230e392e935e5a4d1a187c94f180 Mon Sep 17 00:00:00 2001 From: Konstantin Voykov Date: Sat, 20 Jul 2024 22:49:50 +0300 Subject: [PATCH 1/2] String escaping check policy. --- parser.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/parser.go b/parser.go index a031c2f..1584038 100644 --- a/parser.go +++ b/parser.go @@ -85,13 +85,13 @@ func (vec *Vector) parseGeneric(depth, offset int, node *vector.Node) (int, erro if e < 0 { return n, vector.ErrUnexpEOS } - node.Value().SetBit(flagEscape, false) + node.Value().SetBit(flagEscape, true) // Always mark string as escaped to avoid double indexing. if src[e-1] != '\\' { - // Good case - string isn't escaped. + // Good case - quote isn't escaped. node.Value().SetLen(e - offset - 1) offset = e + 1 } else { - // Walk over double quotas and look for unescaped. + // Walk over quotas and look for unescaped one. for i := e; i < n; { i = bytealg.IndexByteAtBytes(src, '"', i+1) if i < 0 { @@ -104,7 +104,6 @@ func (vec *Vector) parseGeneric(depth, offset int, node *vector.Node) (int, erro } } node.Value().SetLen(e - offset - 1) - node.Value().SetBit(flagEscape, true) offset = e + 1 } case isDigit(src[offset]): From c253c3b21225fbab9249a6bfd0dbd9b754bafe9e Mon Sep 17 00:00:00 2001 From: Konstantin Voykov Date: Sat, 20 Jul 2024 22:50:39 +0300 Subject: [PATCH 2/2] Helper: speedup unescape by using native indexing. --- unescape.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unescape.go b/unescape.go index bc2e0e1..e69950b 100644 --- a/unescape.go +++ b/unescape.go @@ -12,7 +12,7 @@ import ( func Unescape(p []byte) []byte { l, i := len(p), 0 for { - i = bytealg.IndexByteAtLUR(p, '\\', i) + i = bytealg.IndexByteAtBytes(p, '\\', i) if i < 0 || i+1 == l { break }