Skip to content

open and from yaml fail on files with byte-order-mark  #13925

Open
@dcarosone

Description

@dcarosone

Describe the bug

parsing yaml files with a leading UTF-8 byte order mark fails.

Note: I expect this is an upstream issue in the serde_yaml crate. However, there's no way to raise the issue there as the repo has been archived and is no longer maintained.

I have raised an issue in the serde_norway fork: cafkafk/serde-norway#8

There are best-effort maintenance efforts being done there, with important caveats about long-term committment; perhaps nushell should consider switching to that fork, or consider what else to do about that problem. I didn't find an open issue relating to that directly, or I'd have just added the link above there.

How to reproduce

"id: thing\nfoo: bar" | save --raw test1.yaml"id: thing\nfoo: bar" | into binary | bytes add 0x[ef bb bf] | save --raw test2.yamlopen test1.yaml
╭─────┬───────╮
│ id  │ thing │
│ foo │ bar   │
╰─────┴───────╯open test2.yaml
Error:   × Error while parsing as yaml
   ╭─[entry #8:1:6]
 1 │ open test2.yaml
   ·      ─────┬────
   ·           ╰── Could not parse '/tmp/test2.yaml' with `from yaml`
   ╰────
  help: Check out `help from yaml` or `help from` for more options or open raw data with `open --raw '/tmp/test2.yaml'`

Error: nu::shell::unsupported_input

  × Unsupported input
   ╭─[entry #8:1:1]
 1 │ open test2.yaml
   · ──┬─┬
   ·   │ ╰── value originates from here
   ·   ╰── Could not load YAML: did not find expected <document start> at line 2 column 1
   ╰────

# a workaround that removes the BOM againopen --raw test2.yaml | decode utf8 | from yaml
╭─────┬───────╮
│ id  │ thing │
│ foo │ bar   │
╰─────┴───────╯

Expected behavior

parse all my yaml files with just open **/*.yaml rather than needing to glob **/*.yaml | each { open --raw $in | decode utf8 | from yaml }

Configuration

key value
version 0.98.0
major 0
minor 98
patch 0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.80.1 (3f5fd8dd4 2024-08-06) (built from a source tarball)
cargo_version cargo 1.80.0 (376290515 2024-07-16)
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins

Metadata

Metadata

Assignees

No one assigned

    Labels

    file-formatParsing/Writing of file formats/protocolsneeds-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions