@@ -2073,6 +2073,151 @@ public void notCloseUserStreamTest() throws IOException {
2073
2073
Assert .assertEquals (-1 , pdfStream .read ());
2074
2074
}
2075
2075
}
2076
+
2077
+ @ Test
2078
+ @ LogMessages (messages = {
2079
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN )
2080
+ })
2081
+ public void endDicInsteadOfArrayClosingBracketTest () throws IOException {
2082
+ String fileName = SOURCE_FOLDER + "invalidArrayEndDictToken.pdf" ;
2083
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2084
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2085
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2086
+ for (int i = 0 ; i < expected .size (); i ++) {
2087
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2088
+ }
2089
+ }
2090
+
2091
+ @ Test
2092
+ public void endArrayClosingBracketInsteadOfEndDicTest () {
2093
+ String fileName = SOURCE_FOLDER + "endArrayClosingBracketInsteadOfEndDic.pdf" ;
2094
+ Exception exception = Assert .assertThrows (com .itextpdf .io .exceptions .IOException .class ,
2095
+ () -> new PdfDocument (new PdfReader (fileName )));
2096
+ Assert .assertEquals (MessageFormatUtil .format (KernelExceptionMessageConstant .UNEXPECTED_TOKEN , "]" ),
2097
+ exception .getCause ().getMessage ());
2098
+ }
2099
+
2100
+ @ Test
2101
+ public void endDicClosingBracketInsideTheDicTest () {
2102
+ String fileName = SOURCE_FOLDER + "endDicClosingBracketInsideTheDic.pdf" ;
2103
+ Exception exception = Assert .assertThrows (com .itextpdf .io .exceptions .IOException .class ,
2104
+ () -> new PdfDocument (new PdfReader (fileName )));
2105
+ Assert .assertEquals (MessageFormatUtil .format (KernelExceptionMessageConstant .UNEXPECTED_TOKEN , ">>" ),
2106
+ exception .getCause ().getMessage ());
2107
+ }
2108
+
2109
+ @ Test
2110
+ @ LogMessages (messages = {
2111
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN )
2112
+ })
2113
+ public void eofInsteadOfArrayClosingBracketTest () throws IOException {
2114
+ String fileName = SOURCE_FOLDER + "invalidArrayEOFToken.pdf" ;
2115
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2116
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2117
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2118
+ for (int i = 0 ; i < expected .size (); i ++) {
2119
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2120
+ }
2121
+ }
2122
+
2123
+ @ Test
2124
+ @ LogMessages (messages = {
2125
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN )
2126
+ })
2127
+ public void endObjInsteadOfArrayClosingBracketTest () throws IOException {
2128
+ String fileName = SOURCE_FOLDER + "invalidArrayEndObjToken.pdf" ;
2129
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2130
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2131
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2132
+ for (int i = 0 ; i < expected .size (); i ++) {
2133
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2134
+ }
2135
+ }
2136
+
2137
+ @ Test
2138
+ @ LogMessages (messages = {
2139
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN ),
2140
+ @ LogMessage (messageTemplate = IoLogMessageConstant .XREF_ERROR_WHILE_READING_TABLE_WILL_BE_REBUILT )
2141
+ })
2142
+ public void nameInsteadOfArrayClosingBracketTest () throws IOException {
2143
+ String fileName = SOURCE_FOLDER + "invalidArrayNameToken.pdf" ;
2144
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2145
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2146
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2147
+ for (int i = 0 ; i < expected .size (); i ++) {
2148
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2149
+ }
2150
+ }
2151
+
2152
+ @ Test
2153
+ @ LogMessages (messages = {
2154
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN )
2155
+ })
2156
+ public void objInsteadOfArrayClosingBracketTest () throws IOException {
2157
+ String fileName = SOURCE_FOLDER + "invalidArrayObjToken.pdf" ;
2158
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2159
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2160
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2161
+ for (int i = 0 ; i < expected .size (); i ++) {
2162
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2163
+ }
2164
+ }
2165
+
2166
+ @ Test
2167
+ @ LogMessages (messages = {
2168
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN )
2169
+ })
2170
+ public void refInsteadOfArrayClosingBracketTest () throws IOException {
2171
+ String fileName = SOURCE_FOLDER + "invalidArrayRefToken.pdf" ;
2172
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2173
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2174
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2175
+ for (int i = 0 ; i < expected .size (); i ++) {
2176
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2177
+ }
2178
+ }
2179
+
2180
+ @ Test
2181
+ @ LogMessages (messages = {
2182
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN , count = 2 )
2183
+ })
2184
+ public void startArrayInsteadOfArrayClosingBracketTest () throws IOException {
2185
+ String fileName = SOURCE_FOLDER + "invalidArrayStartArrayToken.pdf" ;
2186
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2187
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2188
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2189
+ for (int i = 0 ; i < expected .size (); i ++) {
2190
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2191
+ }
2192
+ }
2193
+
2194
+ @ Test
2195
+ @ LogMessages (messages = {
2196
+ @ LogMessage (messageTemplate = KernelExceptionMessageConstant .UNEXPECTED_TOKEN ),
2197
+ @ LogMessage (messageTemplate = IoLogMessageConstant .XREF_ERROR_WHILE_READING_TABLE_WILL_BE_REBUILT )
2198
+ })
2199
+ public void stringInsteadOfArrayClosingBracketTest () throws IOException {
2200
+ String fileName = SOURCE_FOLDER + "invalidArrayStringToken.pdf" ;
2201
+ PdfDocument document = new PdfDocument (new PdfReader (fileName ));
2202
+ PdfArray actual = (PdfArray ) document .getPdfObject (4 );
2203
+ PdfArray expected = new PdfArray (new float []{5 , 10 , 15 , 20 });
2204
+ for (int i = 0 ; i < expected .size (); i ++) {
2205
+ Assert .assertEquals (expected .get (i ), actual .get (i ));
2206
+ }
2207
+ }
2208
+
2209
+ @ Test
2210
+ public void closingArrayBracketMissingConservativeTest () throws IOException {
2211
+ String fileName = SOURCE_FOLDER + "invalidArrayObjToken.pdf" ;
2212
+ PdfReader reader = new PdfReader (fileName );
2213
+ reader .setStrictnessLevel (StrictnessLevel .CONSERVATIVE );
2214
+ PdfDocument document = new PdfDocument (reader );
2215
+ Exception exception = Assert .assertThrows (com .itextpdf .io .exceptions .IOException .class ,
2216
+ () -> document .getPdfObject (4 ));
2217
+ Assert .assertEquals (MessageFormatUtil .format (KernelExceptionMessageConstant .UNEXPECTED_TOKEN , "obj" ),
2218
+ exception .getCause ().getMessage ());
2219
+ }
2220
+
2076
2221
private static File copyFileForTest (String fileName , String copiedFileName ) throws IOException {
2077
2222
File copiedFile = new File (copiedFileName );
2078
2223
Files .copy (Paths .get (fileName ), Paths .get (copiedFileName ));
0 commit comments