File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -132,8 +132,8 @@ public function has(string $name): bool
132
132
*/
133
133
public function get (string $ name )
134
134
{
135
- if (\array_key_exists ($ name , $ this ->elements )) {
136
- return $ this -> resolveXRef ( $ name ) ;
135
+ if (\array_key_exists ($ name , $ this ->elements ) && $ element = $ this -> resolveXRef ( $ name ) ) {
136
+ return $ element ;
137
137
}
138
138
139
139
return new ElementMissing ();
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ public function __construct(
78
78
?Config $ config = null
79
79
) {
80
80
$ this ->document = $ document ;
81
- $ this ->header = null !== $ header ? $ header : new Header ();
81
+ $ this ->header = $ header ?? new Header ();
82
82
$ this ->content = $ content ;
83
83
$ this ->config = $ config ;
84
84
}
Original file line number Diff line number Diff line change @@ -155,6 +155,18 @@ public function testGet(): void
155
155
$ this ->assertTrue ($ header ->get ('Font ' ) instanceof Page);
156
156
$ this ->assertTrue ($ header ->get ('Image ' ) instanceof ElementMissing);
157
157
$ this ->assertTrue ($ header ->get ('Resources ' ) instanceof ElementMissing);
158
+
159
+ /**
160
+ * A double forward slash in the header's content results in a falsy element
161
+ * that should be parsed to ElementMissing instead.
162
+ *
163
+ * @see https://github.com/smalot/pdfparser/pull/525
164
+ */
165
+ $ content = '<</Type/Page/SubType//Text>>foo ' ;
166
+ $ position = 0 ;
167
+ $ header = Header::parse ($ content , $ document , $ position );
168
+
169
+ $ this ->assertTrue ($ header ->get ('SubType ' ) instanceof ElementMissing);
158
170
}
159
171
160
172
public function testResolveXRef (): void
You can’t perform that action at this time.
0 commit comments