|
24 | 24 |
|
25 | 25 | import java.io.IOException; |
26 | 26 | import java.io.UnsupportedEncodingException; |
| 27 | +import java.nio.ByteBuffer; |
27 | 28 | import java.nio.charset.StandardCharsets; |
28 | 29 |
|
29 | 30 | import org.junit.Test; |
@@ -94,7 +95,7 @@ public void asciiParseLiteral() throws UnsupportedEncodingException |
94 | 95 | } |
95 | 96 |
|
96 | 97 | @Test |
97 | | - public void unitocde8BitsParseLiteral() throws UnsupportedEncodingException |
| 98 | + public void unitocde8BitsParseLiteral() |
98 | 99 | { |
99 | 100 | /** En français où les choses sont accentués. En español, así */ |
100 | 101 | String text8Bit = "En fran\u00e7ais o\u00f9 les choses sont accentu\u00e9s. En espa\u00f1ol, as\u00ed"; |
@@ -159,15 +160,33 @@ private static String createHex(String str) |
159 | 160 | return sb.toString().toUpperCase(); |
160 | 161 | } |
161 | 162 |
|
| 163 | + @Test |
| 164 | + public void utf8EncodedStrings() |
| 165 | + { |
| 166 | + String text = "Det är kallt vid -30°"; |
| 167 | + byte[] utf8Bytes = text.getBytes(StandardCharsets.UTF_8); |
| 168 | + ByteBuffer buffer = ByteBuffer.allocate(3 + utf8Bytes.length); |
| 169 | + // Put the BOM bytes (0xEF, 0xBB, 0xBF) |
| 170 | + buffer.put((byte) 0xEF); |
| 171 | + buffer.put((byte) 0xBB); |
| 172 | + buffer.put((byte) 0xBF); |
| 173 | + |
| 174 | + //Put the original data |
| 175 | + buffer.put(utf8Bytes); |
| 176 | + |
| 177 | + assertEquals(text, new COSString(buffer.array()).getString()); |
| 178 | + } |
| 179 | + |
162 | 180 | /** |
163 | 181 | * PDFBOX-3881: Test that if String has only the BOM, that it be an empty string. |
164 | | - * |
| 182 | + * |
165 | 183 | * @throws IOException |
166 | 184 | */ |
167 | 185 | @Test |
168 | 186 | public void testEmptyStringWithBOM() throws IOException |
169 | 187 | { |
170 | 188 | assertTrue(COSString.parseHex("FEFF").getString().isEmpty()); |
171 | 189 | assertTrue(COSString.parseHex("FFFE").getString().isEmpty()); |
| 190 | + assertTrue(COSString.parseHex("EFBBBF").getString().isEmpty()); |
172 | 191 | } |
173 | 192 | } |
0 commit comments