Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with string escaping. #238

Open
Klafyvel opened this issue Jul 22, 2024 · 2 comments
Open

Problem with string escaping. #238

Klafyvel opened this issue Jul 22, 2024 · 2 comments

Comments

@Klafyvel
Copy link

Hi there,
YAML.jl seems to be producing ill-formated yaml when given the following input:

julia> s
"Attosecond-resolution Hong\uadOu-mandel interferometry"

julia> using YAML

julia> f = tempname()
"/tmp/jl_bShkvctGnQ"

julia> YAML.write_file(f, Dict("a"=>s))

julia> println(String(read(f)))
a: "Attosecond-resolution Hong\uadOu-mandel interferometry"
julia> YAML.load_file(f)
ERROR: while scanning a double-quoted scalar at line 1, column 3: expected escape sequence of 4 hexadecimaldigits, but found 'O' at line 1, column 30
Stacktrace:
  [1] scan_flow_scalar_non_spaces(stream::YAML.TokenStream, double::Bool, start_mark::YAML.Mark)
    @ YAML ~/.julia/packages/YAML/POf8J/src/scanner.jl:1306
  [2] scan_flow_scalar(stream::YAML.TokenStream, style::Char)
    @ YAML ~/.julia/packages/YAML/POf8J/src/scanner.jl:1237
  [3] fetch_flow_scalar
    @ ~/.julia/packages/YAML/POf8J/src/scanner.jl:770 [inlined]
  [4] fetch_double
    @ ~/.julia/packages/YAML/POf8J/src/scanner.jl:758 [inlined]
  [5] fetch_more_tokens(stream::YAML.TokenStream)
    @ YAML ~/.julia/packages/YAML/POf8J/src/scanner.jl:274
  [6] peek(stream::YAML.TokenStream)
    @ YAML ~/.julia/packages/YAML/POf8J/src/scanner.jl:198
  [7] parse_block_mapping_value(stream::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/POf8J/src/parser.jl:461
  [8] peek(stream::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/POf8J/src/parser.jl:54
  [9] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:93
 [10] __compose_mapping_node(event::YAML.ScalarEvent, composer::YAML.Composer, node::YAML.MappingNode)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:154
 [11] _compose_mapping_node(start_event::YAML.MappingStartEvent, composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:174
 [12] compose_mapping_node(composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:183
 [13] handle_event(event::YAML.MappingStartEvent, composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:86
 [14] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:94
 [15] compose_document(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:50
 [16] compose(events::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/POf8J/src/composer.jl:38
 [17] load(ts::YAML.TokenStream, constructor::YAML.Constructor)
    @ YAML ~/.julia/packages/YAML/POf8J/src/YAML.jl:36
 [18] load(ts::YAML.TokenStream, more_constructors::Nothing, multi_constructors::Dict{Any, Any}; dicttype::Type{Dict{Any, Any}}, constructorType::typeof(YAML.SafeConstructor))
    @ YAML ~/.julia/packages/YAML/POf8J/src/YAML.jl:42
 [19] load
    @ ~/.julia/packages/YAML/POf8J/src/YAML.jl:42 [inlined]
 [20] load (repeats 3 times)
    @ ~/.julia/packages/YAML/POf8J/src/YAML.jl:45 [inlined]
 [21] #16
    @ ~/.julia/packages/YAML/POf8J/src/YAML.jl:94 [inlined]
 [22] open(::YAML.var"#16#17"{@Kwargs{}, Tuple{}}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
    @ Base ./io.jl:396
 [23] open
    @ ./io.jl:393 [inlined]
 [24] load_file(::String)
    @ YAML ~/.julia/packages/YAML/POf8J/src/YAML.jl:92
 [25] top-level scope
    @ REPL[40]:1
pkg> st YAML
Project ZoteroToPapis v0.1.0
Status `~/.julia/dev/ZoteroToPapis/Project.toml`
  [ddb6d928] YAML v0.4.11

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
  LD_PRELOAD = /usr/lib64/libstdc++.so.6

This might be related to #108?

@kescobo
Copy link
Collaborator

kescobo commented Jul 22, 2024

I think #108 only deals with keys, but you can try ] add YAML#master and see if the problem persists?

@Klafyvel
Copy link
Author

Klafyvel commented Jul 22, 2024

Hi, I confirm that I can reproduce on master. :)

julia> s = "Attosecond-resolution Hong\uadOu-mandel interferometry"
"Attosecond-resolution Hong\uadOu-mandel interferometry"

julia> using YAML

julia> f = tempname()
"/tmp/jl_RSXODkvU9C"

julia> YAML.write_file(f, Dict("a"=>s))

julia> println(String(read(f)))
a: "Attosecond-resolution Hong\uadOu-mandel interferometry"


julia> YAML.load_file(f)
ERROR: while scanning a double-quoted scalar at line 1, column 3: expected escape sequence of 4 hexadecimaldigits, but found 'O' at line 1, column 30
Stacktrace:
  [1] scan_flow_scalar_non_spaces(stream::YAML.TokenStream, double::Bool, start_mark::YAML.Mark)
    @ YAML ~/.julia/packages/YAML/twmeD/src/scanner.jl:1362
  [2] scan_flow_scalar(stream::YAML.TokenStream, style::Char)
    @ YAML ~/.julia/packages/YAML/twmeD/src/scanner.jl:1293
  [3] fetch_flow_scalar
    @ ~/.julia/packages/YAML/twmeD/src/scanner.jl:762 [inlined]
  [4] fetch_double
    @ ~/.julia/packages/YAML/twmeD/src/scanner.jl:750 [inlined]
  [5] fetch_more_tokens(stream::YAML.TokenStream)
    @ YAML ~/.julia/packages/YAML/twmeD/src/scanner.jl:267
  [6] peek(stream::YAML.TokenStream)
    @ YAML ~/.julia/packages/YAML/twmeD/src/scanner.jl:191
  [7] parse_block_mapping_value(stream::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/twmeD/src/parser.jl:459
  [8] peek(stream::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/twmeD/src/parser.jl:52
  [9] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:87
 [10] __compose_mapping_node(event::YAML.ScalarEvent, composer::YAML.Composer, node::YAML.MappingNode)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:148
 [11] _compose_mapping_node(start_event::YAML.MappingStartEvent, composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:168
 [12] compose_mapping_node(composer::YAML.Composer, anchor::Nothing)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:177
 [13] handle_event(event::YAML.MappingStartEvent, composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:81
 [14] compose_node(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:88
 [15] compose_document(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:46
 [16] compose(events::YAML.EventStream, resolver::YAML.Resolver)
    @ YAML ~/.julia/packages/YAML/twmeD/src/composer.jl:33
 [17] load(tokenstream::YAML.TokenStream, constructor::YAML.Constructor)
    @ YAML ~/.julia/packages/YAML/twmeD/src/YAML.jl:77
 [18] load(ts::YAML.TokenStream, more_constructors::Nothing, multi_constructors::Dict{…}; dicttype::Type{…}, constructorType::typeof(YAML.SafeConstructor))
    @ YAML ~/.julia/packages/YAML/twmeD/src/YAML.jl:84
 [19] load
    @ ~/.julia/packages/YAML/twmeD/src/YAML.jl:84 [inlined]
 [20] load (repeats 3 times)
    @ ~/.julia/packages/YAML/twmeD/src/YAML.jl:87 [inlined]
 [21] #16
    @ ~/.julia/packages/YAML/twmeD/src/YAML.jl:155 [inlined]
 [22] open(::YAML.var"#16#17"{@Kwargs{}, Tuple{}}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
    @ Base ./io.jl:396
 [23] open
    @ ./io.jl:393 [inlined]
 [24] load_file(::String)
    @ YAML ~/.julia/packages/YAML/twmeD/src/YAML.jl:153
 [25] top-level scope
    @ REPL[8]:1
Some type information was truncated. Use `show(err)` to see complete types.

(jl_wPLlVl) pkg> st
Status `/tmp/jl_wPLlVl/Project.toml`
  [ddb6d928] YAML v0.4.11 `https://github.com/JuliaData/YAML.jl.git#master`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants