Skip to content

Commit

Permalink
simplifies new line handling in decode
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-turner committed Nov 28, 2022
1 parent 4943b17 commit 1afbae3
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ To test new implementations of Ecoji, look at the [test script](../test_scripts/
When encoding data, new lines can optionally be inserted to wrap data. Encoding
should normally emit the Unix new line character of `\n` when wrapping, but
could emit '\r\n' if desired. Decoding data ignores all new lines, including
windows new lines. So decoding should ignore `\n` and `\r\n`.
windows new lines. So decoding should ignore `\n` and `\r`.

The Go implementation only emits `\n`, but accepts `\n` or `\r\n`.
The Go implementation only emits `\n`, but accepts `\n` or `\r`.

## Versions

Expand Down
1 change: 0 additions & 1 deletion test_scripts/data/bad_newline_1.garbage

This file was deleted.

1 change: 0 additions & 1 deletion test_scripts/data/bad_newline_2.garbage

This file was deleted.

19 changes: 1 addition & 18 deletions v2/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,8 @@ func readFour(r io.RuneReader, expectedVer *ecojiver, emojis []emojiInfo) (int,
return -1, e
}

// igore \r\n
if c == '\r' {
c, _, e := r.ReadRune()
if e != nil {
if e == io.EOF {
return -1, errors.New("Saw \r that was not followed by \n")
} else {
return -1, e
}
} else if c == '\n' {
//ignore \r\n
continue
} else {
return -1, errors.New("Saw \r that was not followed by \n")
}
}

// ignore new lines
if c == '\n' {
if c == '\n' || c == '\r' {
continue
}

Expand Down
4 changes: 0 additions & 4 deletions v2/ecoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ func TestGarbage(t *testing.T) {
testGarbageInput(t, string(runes8[:]), "Unexpected end of data, input data size not multiple of 4", "missing_padding_1")
runes9 := [5]rune{emojisV2[1], emojisV2[2], emojisV2[3], emojisV2[4], emojisV2[5]}
testGarbageInput(t, string(runes9[:]), "Unexpected end of data, input data size not multiple of 4", "missing_padding_2")

testGarbageInput(t, "🎌\r🚟\rπŸŽ—πŸˆΈπŸŽ₯🀠\rπŸ“ πŸπŸ‘–πŸ“ΈπŸŽˆβ˜•", "Saw \r that was not followed by \n", "bad_newline_1")
testGarbageInput(t, "πŸŽŒπŸšŸπŸŽ—πŸˆΈπŸŽ₯πŸ€ πŸ“ πŸπŸ‘–πŸ“ΈπŸŽˆβ˜•\r", "Saw \r that was not followed by \n", "bad_newline_2")

}

func TestDecodeMixed(t *testing.T) {
Expand Down

0 comments on commit 1afbae3

Please sign in to comment.