[PATCH] D137118: [YAML] Trim trailing whitespace from plain scalars

Rahul Kayaith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 07:56:33 PDT 2022


rkayaith updated this revision to Diff 472303.
rkayaith edited the summary of this revision.
rkayaith added a comment.

update summary


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137118/new/

https://reviews.llvm.org/D137118

Files:
  llvm/lib/Support/YAMLParser.cpp
  llvm/test/YAMLParser/json.test
  llvm/unittests/Support/YAMLIOTest.cpp


Index: llvm/unittests/Support/YAMLIOTest.cpp
===================================================================
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -96,6 +96,15 @@
     EXPECT_EQ(doc.foo, 3);
     EXPECT_EQ(doc.bar, 5);
   }
+
+  {
+    Input yin("{\"foo\": 3\n, \"bar\": 5}");
+    yin >> doc;
+
+    EXPECT_FALSE(yin.error());
+    EXPECT_EQ(doc.foo, 3);
+    EXPECT_EQ(doc.bar, 5);
+  }
 }
 
 TEST(YAMLIO, TestMalformedMapRead) {
Index: llvm/test/YAMLParser/json.test
===================================================================
--- /dev/null
+++ llvm/test/YAMLParser/json.test
@@ -0,0 +1,13 @@
+# RUN: yaml-bench -canonical %s | FileCheck %s
+
+# CHECK: !!map {
+# CHECK:   ? !!str "foo"
+# CHECK:   : !!str "123",
+# CHECK:   ? !!str "bar"
+# CHECK:   : !!str "456",
+# CHECK: }
+
+{
+  "foo": 123,
+  "bar": 456
+}
Index: llvm/lib/Support/YAMLParser.cpp
===================================================================
--- llvm/lib/Support/YAMLParser.cpp
+++ llvm/lib/Support/YAMLParser.cpp
@@ -2042,7 +2042,8 @@
     return UnquotedValue;
   }
   // Plain or block.
-  return Value.rtrim(' ');
+  // Trim whitespace ('b-char' and 's-white').
+  return Value.rtrim("\x0A\x0D\x20\x09");
 }
 
 StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137118.472303.patch
Type: text/x-patch
Size: 1328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221101/d6d4756d/attachment.bin>


More information about the llvm-commits mailing list