[llvm-branch-commits] [llvm] [YAMLParser] Fix handling escaped line breaks in double-quoted scalars (PR #71775)
Igor Kudrin via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 9 15:56:23 PST 2023
https://github.com/igorkudrin updated https://github.com/llvm/llvm-project/pull/71775
>From b4e19d2f0531c99167e3391f3742729c731d9c34 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Wed, 8 Nov 2023 20:48:49 -0800
Subject: [PATCH] [YAMLParser] Fix handling escaped line breaks in
double-quoted scalars
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.
---
llvm/lib/Support/YAMLParser.cpp | 13 ++++++-------
llvm/test/YAMLParser/spec-09-02.test | 2 +-
llvm/test/YAMLParser/spec-09-04.test | 2 +-
llvm/test/YAMLParser/spec1.2-07-05.test | 2 +-
4 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 17d727b6cc07da8..b47cb3ae3b44a75 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -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;
diff --git a/llvm/test/YAMLParser/spec-09-02.test b/llvm/test/YAMLParser/spec-09-02.test
index 6b68a00e3fc3e6f..51ea61dd23273d3 100644
--- a/llvm/test/YAMLParser/spec-09-02.test
+++ b/llvm/test/YAMLParser/spec-09-02.test
@@ -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.
diff --git a/llvm/test/YAMLParser/spec-09-04.test b/llvm/test/YAMLParser/spec-09-04.test
index 1e904eaa70992e5..e4f77ea83c7ac5f 100644
--- a/llvm/test/YAMLParser/spec-09-04.test
+++ b/llvm/test/YAMLParser/spec-09-04.test
@@ -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
diff --git a/llvm/test/YAMLParser/spec1.2-07-05.test b/llvm/test/YAMLParser/spec1.2-07-05.test
index 3ea0e5aa37743e4..f923f68d04295f9 100644
--- a/llvm/test/YAMLParser/spec1.2-07-05.test
+++ b/llvm/test/YAMLParser/spec1.2-07-05.test
@@ -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,
More information about the llvm-branch-commits
mailing list