[llvm-branch-commits] [llvm] b4e19d2 - [YAMLParser] Fix handling escaped line breaks in double-quoted scalars

Igor Kudrin via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 9 15:56:36 PST 2023


Author: Igor Kudrin
Date: 2023-11-09T13:51:04-08:00
New Revision: b4e19d2f0531c99167e3391f3742729c731d9c34

URL: https://github.com/llvm/llvm-project/commit/b4e19d2f0531c99167e3391f3742729c731d9c34
DIFF: https://github.com/llvm/llvm-project/commit/b4e19d2f0531c99167e3391f3742729c731d9c34.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Support/YAMLParser.cpp
    llvm/test/YAMLParser/spec-09-02.test
    llvm/test/YAMLParser/spec-09-04.test
    llvm/test/YAMLParser/spec1.2-07-05.test

Removed: 
    


################################################################################
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