diff --git a/vlib/toml/scanner/scanner.v b/vlib/toml/scanner/scanner.v index a97cf131c7..f1aa696566 100644 --- a/vlib/toml/scanner/scanner.v +++ b/vlib/toml/scanner/scanner.v @@ -516,7 +516,7 @@ fn (mut s Scanner) handle_escapes(quote byte, is_multiline bool) (string, int) { && byte(s.peek(4)).is_hex_digit() && byte(s.peek(5)).is_hex_digit() { lit += s.text[s.pos + 1..s.pos + 6] //.ascii_str() util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'gulp escaped unicode `$lit`') - return lit, 4 + return lit, 5 } else if s.peek(1) == quote { if (!is_multiline && s.peek(2) == `\n`) || (is_multiline && s.peek(2) == quote && s.peek(3) == quote && s.peek(4) == `\n`) { diff --git a/vlib/toml/tests/strings_test.v b/vlib/toml/tests/strings_test.v index e6e0ab0d2c..8e816ad869 100644 --- a/vlib/toml/tests/strings_test.v +++ b/vlib/toml/tests/strings_test.v @@ -28,6 +28,8 @@ two three four '''" + toml_unicode_escapes = r'short = "\u03B4" +long = "\U000003B4"' ) fn test_multiline_strings() { @@ -66,6 +68,15 @@ fn test_multiline_strings() { assert value.string() == 'aaa' + '"""' + 'bbb' } +fn test_unicode_escapes() { + mut toml_doc := toml.parse(toml_unicode_escapes) or { panic(err) } + + mut value := toml_doc.value('short') + assert value.string() == r'\u03B4' + value = toml_doc.value('long') + assert value.string() == r'\U000003B4' +} + fn test_literal_strings() { toml_file := os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) +