Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/libyaml/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ func isPrintable(b []byte, i int) bool {
(b[i] == 0xEE) ||
(b[i] == 0xEF && // #xE000 <= . <= #xFFFD
!(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF
!(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF))))
!(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF))) ||
// 4-byte UTF-8 range for valid Unicode scalars: U+10000..U+10FFFF.
(b[i] == 0xF0 && b[i+1] >= 0x90 && b[i+1] <= 0xBF) ||
(b[i] > 0xF0 && b[i] < 0xF4 && b[i+1] >= 0x80 && b[i+1] <= 0xBF) ||
(b[i] == 0xF4 && b[i+1] >= 0x80 && b[i+1] <= 0x8F))
Comment on lines +631 to +634

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing code doesn't do it either

}

// Check if the character at the specified position is NUL.
Expand Down
24 changes: 24 additions & 0 deletions internal/libyaml/testdata/constructor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,27 @@
- 42
- -10
- 3.14

- scalar-resolution:
name: emojis
yaml: |
- 😀
- 👍🏽
- 🇺🇸
- 🏳️‍🌈
- 👩🏼‍❤️‍💋‍👨🏾
want:
- 😀
- 👍🏽
- 🇺🇸
- 🏳️‍🌈
- 👩🏼‍❤️‍💋‍👨🏾

- scalar-resolution:
name: supplementary non-emoji and mixed scalar
yaml: |
- 𐀀
- A😀𐀀Z
want:
- 𐀀
- A😀𐀀Z
235 changes: 235 additions & 0 deletions internal/libyaml/testdata/emitter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,241 @@
- parent
- child

- emit-config:
name: Various characters from Unicode ranges
conf:
unicode: true
data:
- STREAM_START_EVENT:
encoding: UTF8_ENCODING
- DOCUMENT_START_EVENT:
implicit: false
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: ASCII
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: é
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: ©
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: €
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 𐀀
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 漢
implicit: true
style: PLAIN_SCALAR_STYLE
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT
want: |-
- ASCII
- é
- ©
- €
- 𐀀
- 漢

- emit-config:
name: Emojis with Unicode enabled
conf:
unicode: true
data:
- STREAM_START_EVENT:
encoding: UTF8_ENCODING
- DOCUMENT_START_EVENT:
implicit: true
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: 😀
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 👍🏽
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 🇺🇸
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 🏳️‍🌈
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 👩🏼‍❤️‍💋‍👨🏾
implicit: true
style: PLAIN_SCALAR_STYLE
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT
want: |
- 😀
- 👍🏽
- 🇺🇸
- 🏳️‍🌈
- 👩🏼‍❤️‍💋‍👨🏾

- emit-config:
name: Unicode characters with double quotes and Unicode enabled
conf:
unicode: true
data:
- STREAM_START_EVENT:
encoding: UTF8_ENCODING
- DOCUMENT_START_EVENT:
implicit: false
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: ASCII
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: é
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: ©
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: €
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: 𐀀
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: 漢
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: 😀
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: 🏳️‍🌈
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SCALAR_EVENT:
value: 👩🏼‍❤️‍💋‍👨🏾
implicit: true
style: DOUBLE_QUOTED_SCALAR_STYLE
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT
want:
- "ASCII"
- "é"
- "©"
- "€"
- "𐀀"
- "漢"
- "😀"
- "🏳️‍🌈"
- "👩🏼‍❤️‍💋‍👨🏾"

- emit-config:
name: Emojis with Unicode disabled
conf:
unicode: false
data:
- STREAM_START_EVENT:
encoding: UTF8_ENCODING
- DOCUMENT_START_EVENT:
implicit: true
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: 😀
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 👍🏽
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 🇺🇸
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 🏳️‍🌈
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: 👩🏼‍❤️‍💋‍👨🏾
implicit: true
style: PLAIN_SCALAR_STYLE
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT
want: |
- ! "\U0001F600"
- ! "\U0001F44D\U0001F3FD"
- ! "\U0001F1FA\U0001F1F8"
- ! "\U0001F3F3\uFE0F\u200D\U0001F308"
- ! "\U0001F469\U0001F3FC\u200D\u2764\uFE0F\u200D\U0001F48B\u200D\U0001F468\U0001F3FE"

- emit-config:
name: Supplementary non-emoji and mixed scalar with Unicode enabled
conf:
unicode: true
data:
- STREAM_START_EVENT:
encoding: UTF8_ENCODING
- DOCUMENT_START_EVENT:
implicit: true
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: 𐀀
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: A😀𐀁Z
implicit: true
style: PLAIN_SCALAR_STYLE
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT
want:
- 𐀀
- A😀𐀁Z

- emit-config:
name: Supplementary non-emoji and mixed scalar with Unicode disabled
conf:
unicode: false
data:
- STREAM_START_EVENT:
encoding: UTF8_ENCODING
- DOCUMENT_START_EVENT:
implicit: true
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: 𐀀
implicit: true
style: PLAIN_SCALAR_STYLE
- SCALAR_EVENT:
value: A😀𐀁Z
implicit: true
style: PLAIN_SCALAR_STYLE
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT
want: |
- ! "\U00010000"
- ! "A\U0001F600\U00010001Z"

# Roundtrip test
- roundtrip:
name: Roundtrip
Expand Down
45 changes: 45 additions & 0 deletions internal/libyaml/testdata/parser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,51 @@
- DOCUMENT_END_EVENT
- STREAM_END_EVENT

- parse-events-detailed:
name: Emojis sequence
yaml: |
- 😀
- 👍🏽
- 🇺🇸
- 🏳️‍🌈
- 👩🏼‍❤️‍💋‍👨🏾
want:
- STREAM_START_EVENT
- DOCUMENT_START_EVENT:
implicit: true
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: 😀
- SCALAR_EVENT:
value: 👍🏽
- SCALAR_EVENT:
value: 🇺🇸
- SCALAR_EVENT:
value: 🏳️‍🌈
- SCALAR_EVENT:
value: 👩🏼‍❤️‍💋‍👨🏾
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT

- parse-events-detailed:
name: Supplementary non-emoji and mixed scalar sequence
yaml: |
- 𐀀
- A😀𐀀Z
want:
- STREAM_START_EVENT
- DOCUMENT_START_EVENT:
implicit: true
- SEQUENCE_START_EVENT
- SCALAR_EVENT:
value: 𐀀
- SCALAR_EVENT:
value: A😀𐀀Z
- SEQUENCE_END_EVENT
- DOCUMENT_END_EVENT
- STREAM_END_EVENT

# Error tests
- parse-error:
name: Error state
Expand Down
Loading
Loading