Skip to content

Bug: Empty PdfString decodes into a string of 64 ï characters #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Bug: Empty PdfString decodes into a string of 64 ï characters
  • Loading branch information
tyomitch committed Jul 24, 2023
commit 0a33462f5810c5fc4f61ec27bda0ef00e71a4294
3 changes: 3 additions & 0 deletions kernel/src/main/java/com/itextpdf/kernel/pdf/PdfString.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ protected byte[] decodeContent() {
* @return Hexadecimal string or string with escaped symbols in byte array view.
*/
protected byte[] encodeBytes(byte[] bytes) {
if (bytes.length == 0) {
return bytes;
}
if (hexWriting) {
ByteBuffer buf = new ByteBuffer(bytes.length * 2);
for (byte b : bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,12 @@ public void writeUtf8ActualText() throws java.io.IOException, InterruptedExcepti

Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "writeUtf8ActualText.pdf", sourceFolder + "cmp_writeUtf8ActualText.pdf", destinationFolder, "diffActualText_"));
}

@Test
public void emptyHexWriting() {
PdfString string = new PdfString("");
Assert.assertEquals("", string.toUnicodeString());
string.setHexWriting(true);
Assert.assertEquals("", string.toUnicodeString());
}
}