diff --git a/Tests/LibPDF/TestPDF.cpp b/Tests/LibPDF/TestPDF.cpp index 319aa374884..14c643d1124 100644 --- a/Tests/LibPDF/TestPDF.cpp +++ b/Tests/LibPDF/TestPDF.cpp @@ -15,6 +15,27 @@ #include #include +TEST_CASE(parse_value) +{ + // document isn't really used for anything, only to check there's no security_handler. + auto file = MUST(Core::MappedFile::map("linearized.pdf"sv)); + auto document = MUST(PDF::Document::create(file->bytes())); + + auto contents = "<50607><10\n>"sv; + PDF::Parser parser(contents.bytes()); + parser.set_document(document->make_weak_ptr()); + + auto value1 = MUST(parser.parse_value(PDF::Parser::CanBeIndirectValue::No)); + auto string1 = value1.get>()->cast(); + EXPECT(string1->is_binary()); + EXPECT_EQ(string1->string(), "\x50\x60\x70"sv); + + auto value2 = MUST(parser.parse_value(PDF::Parser::CanBeIndirectValue::No)); + auto string2 = value2.get>()->cast(); + EXPECT(string2->is_binary()); + EXPECT_EQ(string2->string(), "\x10"sv); +} + TEST_CASE(linearized_pdf) { auto file = MUST(Core::MappedFile::map("linearized.pdf"sv)); diff --git a/Userland/Libraries/LibPDF/Parser.cpp b/Userland/Libraries/LibPDF/Parser.cpp index a6d60dabbc9..30cc6d95dcb 100644 --- a/Userland/Libraries/LibPDF/Parser.cpp +++ b/Userland/Libraries/LibPDF/Parser.cpp @@ -352,6 +352,7 @@ PDFErrorOr Parser::parse_hex_string() StringBuilder builder; while (true) { + m_reader.consume_whitespace(); if (m_reader.matches('>')) { m_reader.consume(); return builder.to_byte_string(); @@ -364,7 +365,6 @@ PDFErrorOr Parser::parse_hex_string() if (ch == '>') { // The hex string contains an odd number of characters, and the last character // is assumed to be '0' - m_reader.consume(); hex_value *= 16; builder.append(static_cast(hex_value)); return builder.to_byte_string();