Skip to content

Commit 1afbae3

Browse files
committed
simplifies new line handling in decode
1 parent 4943b17 commit 1afbae3

File tree

5 files changed

+3
-26
lines changed

5 files changed

+3
-26
lines changed

docs/encoding.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ To test new implementations of Ecoji, look at the [test script](../test_scripts/
3030
When encoding data, new lines can optionally be inserted to wrap data. Encoding
3131
should normally emit the Unix new line character of `\n` when wrapping, but
3232
could emit '\r\n' if desired. Decoding data ignores all new lines, including
33-
windows new lines. So decoding should ignore `\n` and `\r\n`.
33+
windows new lines. So decoding should ignore `\n` and `\r`.
3434

35-
The Go implementation only emits `\n`, but accepts `\n` or `\r\n`.
35+
The Go implementation only emits `\n`, but accepts `\n` or `\r`.
3636

3737
## Versions
3838

test_scripts/data/bad_newline_1.garbage

-1
This file was deleted.

test_scripts/data/bad_newline_2.garbage

-1
This file was deleted.

v2/decode.go

+1-18
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,8 @@ func readFour(r io.RuneReader, expectedVer *ecojiver, emojis []emojiInfo) (int,
3333
return -1, e
3434
}
3535

36-
// igore \r\n
37-
if c == '\r' {
38-
c, _, e := r.ReadRune()
39-
if e != nil {
40-
if e == io.EOF {
41-
return -1, errors.New("Saw \r that was not followed by \n")
42-
} else {
43-
return -1, e
44-
}
45-
} else if c == '\n' {
46-
//ignore \r\n
47-
continue
48-
} else {
49-
return -1, errors.New("Saw \r that was not followed by \n")
50-
}
51-
}
52-
5336
// ignore new lines
54-
if c == '\n' {
37+
if c == '\n' || c == '\r' {
5538
continue
5639
}
5740

v2/ecoji_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,6 @@ func TestGarbage(t *testing.T) {
332332
testGarbageInput(t, string(runes8[:]), "Unexpected end of data, input data size not multiple of 4", "missing_padding_1")
333333
runes9 := [5]rune{emojisV2[1], emojisV2[2], emojisV2[3], emojisV2[4], emojisV2[5]}
334334
testGarbageInput(t, string(runes9[:]), "Unexpected end of data, input data size not multiple of 4", "missing_padding_2")
335-
336-
testGarbageInput(t, "🎌\r🚟\r🎗🈸🎥🤠\r📠🐁👖📸🎈☕", "Saw \r that was not followed by \n", "bad_newline_1")
337-
testGarbageInput(t, "🎌🚟🎗🈸🎥🤠📠🐁👖📸🎈☕\r", "Saw \r that was not followed by \n", "bad_newline_2")
338-
339335
}
340336

341337
func TestDecodeMixed(t *testing.T) {

0 commit comments

Comments
 (0)