Add unit test for SimpleParserTest regression
Demonstrate how CPDF_SimpleParser cannot parse "foo <> bar" correctly.
Bug: 358381390
Change-Id: Iebeb65077f67d8ace4e8cf04c6df54cb6dc4cd4c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/123330
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
index f2ec6d3..ff2eaeb 100644
--- a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp
@@ -59,3 +59,17 @@
++i;
}
}
+
+TEST(SimpleParserTest, Bug358381390) {
+ const char kInput[] = "1 beginbfchar\n<01> <>\nendbfchar\n1 beginbfchar";
+
+ CPDF_SimpleParser parser(pdfium::as_byte_span(kInput));
+ EXPECT_EQ(parser.GetWord(), "1");
+ EXPECT_EQ(parser.GetWord(), "beginbfchar");
+ EXPECT_EQ(parser.GetWord(), "<01>");
+ // TODO(crbug.com/358381390): Should parse to:
+ // {"<>", "endbfchar", "1", "beginbfchar"}
+ // Note that the span below includes the NUL at the end of the string.
+ const char kWrongResult[] = "<>\nendbfchar\n1 beginbfchar";
+ EXPECT_EQ(parser.GetWord(), ByteStringView(pdfium::make_span(kWrongResult)));
+}