1717use PHPHtmlParser \Exceptions \LogicalException ;
1818use PHPHtmlParser \Exceptions \StrictException ;
1919use PHPHtmlParser \Options ;
20- use stringEncode \ Encode ;
20+ use StringEncoder \ Encoder ;
2121
2222class Parser implements ParserInterface
2323{
@@ -37,7 +37,7 @@ public function parse(Options $options, Content $content, int $size): AbstractNo
3737 $ root ->setHtmlSpecialCharsDecode ($ options ->isHtmlSpecialCharsDecode ());
3838 $ activeNode = $ root ;
3939 while ($ activeNode !== null ) {
40- if ($ activeNode && $ activeNode ->tag ->name () === 'script '
40+ if ($ activeNode && is_object ( $ activeNode -> tag ) && $ activeNode ->tag ->name () === 'script '
4141 && $ options ->isCleanupInput () !== true
4242 ) {
4343 $ str = $ content ->copyUntil ('</ ' );
@@ -104,15 +104,15 @@ public function parse(Options $options, Content $content, int $size): AbstractNo
104104 public function detectCharset (Options $ options , string $ defaultCharset , AbstractNode $ root ): bool
105105 {
106106 // set the default
107- $ encode = new Encode ();
108- $ encode ->from ($ defaultCharset );
109- $ encode ->to ($ defaultCharset );
107+ $ encode = new Encoder ();
108+ $ encode ->setSourceEncoding ($ defaultCharset );
109+ $ encode ->setTargetEncoding ($ defaultCharset );
110110
111111 $ enforceEncoding = $ options ->getEnforceEncoding ();
112112 if ($ enforceEncoding !== null ) {
113113 // they want to enforce the given encoding
114- $ encode ->from ($ enforceEncoding );
115- $ encode ->to ($ enforceEncoding );
114+ $ encode ->setSourceEncoding ($ enforceEncoding );
115+ $ encode ->setTargetEncoding ($ enforceEncoding );
116116
117117 return false ;
118118 }
@@ -138,7 +138,7 @@ public function detectCharset(Options $options, string $defaultCharset, Abstract
138138 }
139139 $ matches = [];
140140 if (\preg_match ('/charset=([^;]+)/ ' , $ content , $ matches )) {
141- $ encode ->from (\trim ($ matches [1 ]));
141+ $ encode ->setSourceEncoding (\trim ($ matches [1 ]));
142142 $ root ->propagateEncoding ($ encode );
143143
144144 return true ;
@@ -169,6 +169,7 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO
169169 try {
170170 $ content ->fastForward (1 );
171171 } catch (ContentLengthException $ exception ) {
172+ unset($ exception );
172173 // we are at the end of the file
173174 return TagDTO::makeFromPrimitives ();
174175 }
@@ -183,7 +184,7 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO
183184 ->setOpening ('<? ' )
184185 ->setClosing (' ?> ' )
185186 ->selfClosing ();
186- } elseif ($ content ->string (3 ) == '!-- ' ) {
187+ } elseif ($ content ->string (3 ) == '!-- ' ) {
187188 // comment tag
188189 $ tag = $ content ->fastForward (3 )
189190 ->copyByToken (StringToken::CLOSECOMMENT (), true );
@@ -233,15 +234,15 @@ private function parseTag(Options $options, Content $content, int $size): TagDTO
233234 /**
234235 * @throws ChildNotFoundException
235236 */
236- private function detectHTML5Charset (Encode $ encode , AbstractNode $ root ): bool
237+ private function detectHTML5Charset (Encoder $ encode , AbstractNode $ root ): bool
237238 {
238239 /** @var AbstractNode|null $meta */
239240 $ meta = $ root ->find ('meta[charset] ' , 0 );
240241 if ($ meta == null ) {
241242 return false ;
242243 }
243244
244- $ encode ->from (\trim ($ meta ->getAttribute ('charset ' )));
245+ $ encode ->setSourceEncoding (\trim ($ meta ->getAttribute ('charset ' )));
245246 $ root ->propagateEncoding ($ encode );
246247
247248 return true ;
@@ -286,6 +287,7 @@ private function setUpAttributes(Content $content, int $size, HtmlNode $node, Op
286287 try {
287288 $ content ->fastForward (1 );
288289 } catch (ContentLengthException $ exception ) {
290+ unset($ exception );
289291 // reached the end of the content
290292 break ;
291293 }
0 commit comments