[all-commits] [llvm/llvm-project] 32b3f1: [YAML] Trim trailing whitespace from plain scalars

rk via All-commits all-commits at lists.llvm.org
Thu Feb 9 18:57:11 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 32b3f13337ef0bf747705d058f4772c7fdabd736
      https://github.com/llvm/llvm-project/commit/32b3f13337ef0bf747705d058f4772c7fdabd736
  Author: rkayaith <rkayaith at gmail.com>
  Date:   2023-02-09 (Thu, 09 Feb 2023)

  Changed paths:
    M llvm/lib/Support/YAMLParser.cpp
    A llvm/test/YAMLParser/json.test
    M llvm/unittests/Support/YAMLIOTest.cpp

  Log Message:
  -----------
  [YAML] Trim trailing whitespace from plain scalars

In some cases plain scalars are currently parsed with a trailing
newline. In particular this shows up often when parsing JSON files, e.g.
note the `\n` after `456` below:
```
$ cat test.yaml
{
  "foo": 123,
  "bar": 456
}
$ yaml-bench test.yaml -canonical
%YAML 1.2
---
!!map {
  ? !!str "foo"
  : !!str "123",
  ? !!str "bar"
  : !!str "456\n",
}
...
```
The trailing whitespace ends up causing the conversion of the scalar to
int/bool/etc. to fail, causing the issue seen here:
https://github.com/llvm/llvm-project/issues/15877

>From reading the YAML spec (https://yaml.org/spec/1.2.2/#733-plain-style)
it seems like plain scalars should never end with whitespace, so this
change trims all trailing whitespace characters from the
value (specifically `b-line-feed`, `b-carriage-return`, `s-space`, and
`s-tab`).

Reviewed By: scott.linder

Differential Revision: https://reviews.llvm.org/D137118




More information about the All-commits mailing list