Skip to content

Commit

Permalink
[YAMLParser] Fix handling escaped line breaks in double-quoted scalars
Browse files Browse the repository at this point in the history
Leading white spaces on the line following an escaped line break should
be excluded from the content.
See https://yaml.org/spec/1.2.2/#731-double-quoted-style.
  • Loading branch information
igorkudrin committed Nov 10, 2023
1 parent a5a0248 commit b9b9c49
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions llvm/lib/Support/YAMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2107,14 +2107,13 @@ StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
return "";
}
case '\r':
// Shrink the Windows-style EOL.
if (UnquotedValue.size() >= 2 && UnquotedValue[1] == '\n')
UnquotedValue = UnquotedValue.drop_front(1);
[[fallthrough]];
case '\n':
// Remove the new line.
if ( UnquotedValue.size() > 1
&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
UnquotedValue = UnquotedValue.substr(1);
// If this was just a single byte newline, it will get skipped
// below.
break;
UnquotedValue = UnquotedValue.drop_front(1).ltrim(" \t");
continue;
case '0':
Storage.push_back(0x00);
break;
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/YAMLParser/spec-09-02.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s --strict-whitespace
# CHECK: "as space\n trimmed \n specific\L\n escaped\t \n none"
# CHECK: "as space\n trimmed \n specific\L\n escaped\t\n none"

## Note: The example was originally taken from Spec 1.1, but the parsing rules
## have been changed since then.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/YAMLParser/spec-09-04.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml-bench -canonical %s | FileCheck %s --strict-whitespace
# CHECK: "first\n \tinner 1\t\n inner 2 last"
# CHECK: "first\n \tinner 1\t\n inner 2 last"

"first
inner 1
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/YAMLParser/spec1.2-07-05.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml-bench -canonical %s | FileCheck %s --strict-whitespace
# CHECK: "folded \nto a space,\t\n \nto a line feed, or \t \tnon-content"
# CHECK: "folded \nto a space,\t\n \nto a line feed, or \t \tnon-content"

"folded
to a space,
Expand Down

0 comments on commit b9b9c49

Please sign in to comment.