Comments (5)
That's very odd, as there are several tests that verify that. Can you share the exact code/JSON that triggers this?
On Jun 14, 2016 00:13, "Juho Mäkinen" [email protected] wrote:
A JSON text containing the two characters \n (bytes 0x5C and 0x6E) is not
translated to a new line (byte 0x0A).This is explained for example in
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
in page 4: "There are two-character escape sequence representations of some
characters." with the following list: ", , /, \b, \f, \n, \r and \t—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#49, or mute the thread
https://github.com/notifications/unsubscribe/ADvi_vbebLGcZLVDnzbvsEFCGaCRVAfWks5qLipzgaJpZM4I08jG
.
from jsonparser.
Of course. I also realises that I didn't explain what's actually happening: It seems that GetString converts two byte sequence \n into just a single byte n instead of a single byte new-line
func TestENDL(t *testing.T) {
s, _ := jsonparser.GetString([]byte("{\"multiline\":\"line 1\\nline 2\"}"), "multiline")
assert.Equal(t, string(s), "line 1\nline2") // Not equal: "line 1nline 2" != "line 1\nline2"
}
That's the test case which I used to pinpoint the problem. I also added (what I think is a correct test case) test case {in: "\\n", out: "\n", canAlloc: true},
into the escape_test.go into the unescapeTest{} structure (as in this diff):
vagrant@precise64:/Development/jsonparser$ git diff
diff --git a/escape_test.go b/escape_test.go
index db18108..0fb5d22 100644
--- a/escape_test.go
+++ b/escape_test.go
@@ -125,6 +125,7 @@ var unescapeTests = []unescapeTest{
{in: `abcde\uD800`, isErr: true},
{in: `ab\uD800de`, isErr: true},
{in: `\uD800abcde`, isErr: true},
+ {in: "\\n", out: "\n", canAlloc: true},
}
which fails in the following way:
=== RUN TestUnescape
--- FAIL: TestUnescape (0.00s)
escape_test.go:183: Unescape(`\n`, bufsize=0) returned unescaped mismatch: expected `
` ([10], len 1), obtained `n` ([110], len 1)
What do you think? I didn't test any other items in the list than \n
from jsonparser.
Here's another code snippet with the built-int encoding/json package which will encode a field with a new line character into a literal two-byte string \n
type MultiLineJSON struct {
Foobar string
}
func TestENDL2(t *testing.T) {
m := MultiLineJSON{"line 1\nline 2"}
b, _ := json.Marshal(m)
// Will print MultiLineJSON: '{"Foobar":"line 1\nline 2"}'
fmt.Printf("MultiLineJSON: '%s'\n", b)
}
from jsonparser.
There's no question that \n
should escape to a newline.
Uhm, wow. I thought we had tests for this, but apparently they don't quite test this, and the Unescape function does indeed have the error you identified. I will submit a PR very soon to fix this. Thanks for finding this!
from jsonparser.
Thank you both :)
from jsonparser.
Related Issues (20)
- How to break in ArrayEach ?
- Continuing iteration in ArrayEach() HOT 1
- The set function does not work
- package github.com/buger/jsonparser is not a main package HOT 3
- Get call panics on empty json array or invalid json with an empty path - expecting an error to be returned
- [Proposal] New function based on EachKey
- Iterator support for Arrays & Objects
- Dead / Faulty code in ArrayEach? HOT 2
- The maximum number of byte files that ArrayEach supports
- Security - CVE-2020-10675 HOT 5
- Are there plans to release a new version?
- I don`t why it is not work
- how can i get length of array attribute
- ArrayEach correct behaviour
- Delete func data cannot has blank character
- Why were the patch versions for CVE-2020-10675 released so late?
- How to get key by index? HOT 3
- Set with index overrides always first position of the array
- Set() doesnt return a normal json data
- Add Native Support for Retrieving uint64
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonparser.