Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| InHeadNoscript | |
0.00% |
0 / 57 |
|
0.00% |
0 / 4 |
380 | |
0.00% |
0 / 1 |
| characters | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
| startTag | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
132 | |||
| endTag | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
| endDocument | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\TreeBuilder; |
| 5 | |
| 6 | use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 7 | |
| 8 | /** |
| 9 | * The "in head noscript" insertion mode |
| 10 | */ |
| 11 | class InHeadNoscript extends InsertionMode { |
| 12 | /** @inheritDoc */ |
| 13 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 14 | $builder = $this->builder; |
| 15 | $dispatcher = $this->dispatcher; |
| 16 | |
| 17 | // Insert whitespace |
| 18 | [ $part1, $part2 ] = $this->splitInitialMatch( true, "\t\n\f\r ", |
| 19 | $text, $start, $length, $sourceStart, $sourceLength ); |
| 20 | [ $start, $length, $sourceStart, $sourceLength ] = $part1; |
| 21 | if ( $length ) { |
| 22 | $dispatcher->inHead->characters( |
| 23 | $text, $start, $length, $sourceStart, $sourceLength ); |
| 24 | } |
| 25 | |
| 26 | // Switch mode on non-whitespace |
| 27 | [ $start, $length, $sourceStart, $sourceLength ] = $part2; |
| 28 | if ( $length ) { |
| 29 | $builder->error( "unexpected non-whitespace character in head in noscript, " . |
| 30 | "closing noscript", $sourceStart ); |
| 31 | $builder->pop( $sourceStart, 0 ); |
| 32 | $dispatcher->switchMode( Dispatcher::IN_HEAD ) |
| 33 | ->characters( $text, $start, $length, $sourceStart, $sourceLength ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** @inheritDoc */ |
| 38 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 39 | $builder = $this->builder; |
| 40 | $dispatcher = $this->dispatcher; |
| 41 | |
| 42 | switch ( $name ) { |
| 43 | case 'html': |
| 44 | $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 45 | break; |
| 46 | |
| 47 | case 'basefont': |
| 48 | case 'bgsound': |
| 49 | case 'link': |
| 50 | case 'meta': |
| 51 | case 'noframes': |
| 52 | case 'style': |
| 53 | $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 54 | break; |
| 55 | |
| 56 | case 'head': |
| 57 | case 'noscript': |
| 58 | $builder->error( "unexpected <$name> in head in noscript, ignoring", $sourceStart ); |
| 59 | return; |
| 60 | |
| 61 | default: |
| 62 | $builder->error( "unexpected <$name> in head in noscript, closing noscript", |
| 63 | $sourceStart ); |
| 64 | $builder->pop( $sourceStart, 0 ); |
| 65 | $dispatcher->switchMode( Dispatcher::IN_HEAD ) |
| 66 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** @inheritDoc */ |
| 71 | public function endTag( $name, $sourceStart, $sourceLength ) { |
| 72 | $builder = $this->builder; |
| 73 | $dispatcher = $this->dispatcher; |
| 74 | |
| 75 | switch ( $name ) { |
| 76 | case 'noscript': |
| 77 | $builder->pop( $sourceStart, $sourceLength ); |
| 78 | $dispatcher->switchMode( Dispatcher::IN_HEAD ); |
| 79 | break; |
| 80 | |
| 81 | case 'br': |
| 82 | $builder->error( "unexpected </br> in head in noscript, closing noscript", |
| 83 | $sourceStart ); |
| 84 | $builder->pop( $sourceStart, 0 ); |
| 85 | $dispatcher->switchMode( Dispatcher::IN_HEAD ) |
| 86 | ->endTag( $name, $sourceStart, $sourceLength ); |
| 87 | break; |
| 88 | |
| 89 | default: |
| 90 | $builder->error( "unexpected </$name> in head in noscript, ignoring", |
| 91 | $sourceStart ); |
| 92 | return; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** @inheritDoc */ |
| 97 | public function endDocument( $pos ) { |
| 98 | $this->builder->error( "unexpected end-of-file in head in noscript", $pos ); |
| 99 | $this->builder->pop( $pos, 0 ); |
| 100 | $this->dispatcher->switchMode( Dispatcher::IN_HEAD ) |
| 101 | ->endDocument( $pos ); |
| 102 | } |
| 103 | } |