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

Crashes if yaml file contains only a comment #129

Closed
OmegaLambda1998 opened this issue Jan 17, 2023 · 6 comments
Closed

Crashes if yaml file contains only a comment #129

OmegaLambda1998 opened this issue Jan 17, 2023 · 6 comments
Labels

Comments

@OmegaLambda1998
Copy link

Given the yaml file:

# Test

The following code crashes:

using YAML
open("test.yaml", "r") do io
    YAML.load(io)
end

With the error:

ERROR: AssertionError: typeof(forward!(composer.input)) == DocumentStartEvent
Stacktrace:
  [1] compose_document(composer::YAML.Composer)
    @ YAML ~/.julia/packages/YAML/78yP9/src/composer.jl:49
  [2] compose(events::YAML.EventStream)
    @ YAML ~/.julia/packages/YAML/78yP9/src/composer.jl:38
  [3] load(ts::YAML.TokenStream, constructor::YAML.Constructor)
    @ YAML ~/.julia/packages/YAML/78yP9/src/YAML.jl:38
  [4] 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/78yP9/src/YAML.jl:44
  [5] load
    @ ~/.julia/packages/YAML/78yP9/src/YAML.jl:44 [inlined]
  [6] #load#10
    @ ~/.julia/packages/YAML/78yP9/src/YAML.jl:47 [inlined]
  [7] load (repeats 3 times)
    @ ~/.julia/packages/YAML/78yP9/src/YAML.jl:47 [inlined]
  [8] #load#13
    @ ~/.julia/packages/YAML/78yP9/src/YAML.jl:88 [inlined]
  [9] load(::String)
    @ YAML ~/.julia/packages/YAML/78yP9/src/YAML.jl:88
 [10] top-level scope
    @ REPL[7]:1

You can get an even quicker crash via:

YAML.load("#")
@OmegaLambda1998
Copy link
Author

I'd expect this to return an empty dictionary, rather than crashing

@kescobo
Copy link
Collaborator

kescobo commented Jan 17, 2023

It's valid YAML according to https://www.yamllint.com/

@Paalon
Copy link
Contributor

Paalon commented Jun 3, 2024

Result from YPaste Interactive Parser.

スクリーンショット 2024-06-03 19 50 07

I think this should not return an empty dictionary because it's different.
スクリーンショット 2024-06-03 19 52 45

@Paalon
Copy link
Contributor

Paalon commented Jun 3, 2024

This YAML file # represents no document (0 documents).

@Paalon
Copy link
Contributor

Paalon commented Jun 13, 2024

This is not a bug for the same reason as #143. But this is hard to notice that this is intentional.

@GunnarFarneback
Copy link
Contributor

This crash was never intentional. #219 fixed it to return nothing. Returning an empty dictionary is indeed not an option.

@kescobo kescobo closed this as completed Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants