Skip to content

Commit 7cdc906

Browse files
authored
toml: fix scanning of short unicode escapes (#12491)
1 parent 3e1fb22 commit 7cdc906

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

vlib/toml/scanner/scanner.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ fn (mut s Scanner) handle_escapes(quote byte, is_multiline bool) (string, int) {
516516
&& byte(s.peek(4)).is_hex_digit() && byte(s.peek(5)).is_hex_digit() {
517517
lit += s.text[s.pos + 1..s.pos + 6] //.ascii_str()
518518
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'gulp escaped unicode `$lit`')
519-
return lit, 4
519+
return lit, 5
520520
} else if s.peek(1) == quote {
521521
if (!is_multiline && s.peek(2) == `\n`)
522522
|| (is_multiline && s.peek(2) == quote && s.peek(3) == quote && s.peek(4) == `\n`) {

vlib/toml/tests/strings_test.v

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ two
2828
three
2929
four
3030
'''"
31+
toml_unicode_escapes = r'short = "\u03B4"
32+
long = "\U000003B4"'
3133
)
3234

3335
fn test_multiline_strings() {
@@ -66,6 +68,15 @@ fn test_multiline_strings() {
6668
assert value.string() == 'aaa' + '"""' + 'bbb'
6769
}
6870

71+
fn test_unicode_escapes() {
72+
mut toml_doc := toml.parse(toml_unicode_escapes) or { panic(err) }
73+
74+
mut value := toml_doc.value('short')
75+
assert value.string() == r'\u03B4'
76+
value = toml_doc.value('long')
77+
assert value.string() == r'\U000003B4'
78+
}
79+
6980
fn test_literal_strings() {
7081
toml_file :=
7182
os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) +

0 commit comments

Comments
 (0)