PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/external_lib/HTMLPurifier/HTMLPurifier/Lexer/PH5P.php

https://github.com/OwlManAtt/kittokittokitto
PHP | 3906 lines | 1979 code | 614 blank | 1313 comment | 305 complexity | 0f6893d064ab38c573384140159dd275 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Experimental HTML5-based parser using Jeroen van der Meer's PH5P library.
  4. * Occupies space in the HTML5 pseudo-namespace, which may cause conflicts.
  5. *
  6. * @note
  7. * Recent changes to PHP's DOM extension have resulted in some fatal
  8. * error conditions with the original version of PH5P. Pending changes,
  9. * this lexer will punt to DirectLex if DOM throughs an exception.
  10. */
  11. class HTMLPurifier_Lexer_PH5P extends HTMLPurifier_Lexer_DOMLex {
  12. public function tokenizeHTML($html, $config, $context) {
  13. $new_html = $this->normalize($html, $config, $context);
  14. $new_html = $this->wrapHTML($new_html, $config, $context);
  15. try {
  16. $parser = new HTML5($new_html);
  17. $doc = $parser->save();
  18. } catch (DOMException $e) {
  19. // Uh oh, it failed. Punt to DirectLex.
  20. $lexer = new HTMLPurifier_Lexer_DirectLex();
  21. $context->register('PH5PError', $e); // save the error, so we can detect it
  22. return $lexer->tokenizeHTML($html, $config, $context); // use original HTML
  23. }
  24. $tokens = array();
  25. $this->tokenizeDOM(
  26. $doc->getElementsByTagName('html')->item(0)-> // <html>
  27. getElementsByTagName('body')->item(0)-> // <body>
  28. getElementsByTagName('div')->item(0) // <div>
  29. , $tokens);
  30. return $tokens;
  31. }
  32. }
  33. /*
  34. Copyright 2007 Jeroen van der Meer <http://jero.net/>
  35. Permission is hereby granted, free of charge, to any person obtaining a
  36. copy of this software and associated documentation files (the
  37. "Software"), to deal in the Software without restriction, including
  38. without limitation the rights to use, copy, modify, merge, publish,
  39. distribute, sublicense, and/or sell copies of the Software, and to
  40. permit persons to whom the Software is furnished to do so, subject to
  41. the following conditions:
  42. The above copyright notice and this permission notice shall be included
  43. in all copies or substantial portions of the Software.
  44. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  45. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  46. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  47. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  48. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  49. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  50. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  51. */
  52. class HTML5 {
  53. private $data;
  54. private $char;
  55. private $EOF;
  56. private $state;
  57. private $tree;
  58. private $token;
  59. private $content_model;
  60. private $escape = false;
  61. private $entities = array('AElig;','AElig','AMP;','AMP','Aacute;','Aacute',
  62. 'Acirc;','Acirc','Agrave;','Agrave','Alpha;','Aring;','Aring','Atilde;',
  63. 'Atilde','Auml;','Auml','Beta;','COPY;','COPY','Ccedil;','Ccedil','Chi;',
  64. 'Dagger;','Delta;','ETH;','ETH','Eacute;','Eacute','Ecirc;','Ecirc','Egrave;',
  65. 'Egrave','Epsilon;','Eta;','Euml;','Euml','GT;','GT','Gamma;','Iacute;',
  66. 'Iacute','Icirc;','Icirc','Igrave;','Igrave','Iota;','Iuml;','Iuml','Kappa;',
  67. 'LT;','LT','Lambda;','Mu;','Ntilde;','Ntilde','Nu;','OElig;','Oacute;',
  68. 'Oacute','Ocirc;','Ocirc','Ograve;','Ograve','Omega;','Omicron;','Oslash;',
  69. 'Oslash','Otilde;','Otilde','Ouml;','Ouml','Phi;','Pi;','Prime;','Psi;',
  70. 'QUOT;','QUOT','REG;','REG','Rho;','Scaron;','Sigma;','THORN;','THORN',
  71. 'TRADE;','Tau;','Theta;','Uacute;','Uacute','Ucirc;','Ucirc','Ugrave;',
  72. 'Ugrave','Upsilon;','Uuml;','Uuml','Xi;','Yacute;','Yacute','Yuml;','Zeta;',
  73. 'aacute;','aacute','acirc;','acirc','acute;','acute','aelig;','aelig',
  74. 'agrave;','agrave','alefsym;','alpha;','amp;','amp','and;','ang;','apos;',
  75. 'aring;','aring','asymp;','atilde;','atilde','auml;','auml','bdquo;','beta;',
  76. 'brvbar;','brvbar','bull;','cap;','ccedil;','ccedil','cedil;','cedil',
  77. 'cent;','cent','chi;','circ;','clubs;','cong;','copy;','copy','crarr;',
  78. 'cup;','curren;','curren','dArr;','dagger;','darr;','deg;','deg','delta;',
  79. 'diams;','divide;','divide','eacute;','eacute','ecirc;','ecirc','egrave;',
  80. 'egrave','empty;','emsp;','ensp;','epsilon;','equiv;','eta;','eth;','eth',
  81. 'euml;','euml','euro;','exist;','fnof;','forall;','frac12;','frac12',
  82. 'frac14;','frac14','frac34;','frac34','frasl;','gamma;','ge;','gt;','gt',
  83. 'hArr;','harr;','hearts;','hellip;','iacute;','iacute','icirc;','icirc',
  84. 'iexcl;','iexcl','igrave;','igrave','image;','infin;','int;','iota;',
  85. 'iquest;','iquest','isin;','iuml;','iuml','kappa;','lArr;','lambda;','lang;',
  86. 'laquo;','laquo','larr;','lceil;','ldquo;','le;','lfloor;','lowast;','loz;',
  87. 'lrm;','lsaquo;','lsquo;','lt;','lt','macr;','macr','mdash;','micro;','micro',
  88. 'middot;','middot','minus;','mu;','nabla;','nbsp;','nbsp','ndash;','ne;',
  89. 'ni;','not;','not','notin;','nsub;','ntilde;','ntilde','nu;','oacute;',
  90. 'oacute','ocirc;','ocirc','oelig;','ograve;','ograve','oline;','omega;',
  91. 'omicron;','oplus;','or;','ordf;','ordf','ordm;','ordm','oslash;','oslash',
  92. 'otilde;','otilde','otimes;','ouml;','ouml','para;','para','part;','permil;',
  93. 'perp;','phi;','pi;','piv;','plusmn;','plusmn','pound;','pound','prime;',
  94. 'prod;','prop;','psi;','quot;','quot','rArr;','radic;','rang;','raquo;',
  95. 'raquo','rarr;','rceil;','rdquo;','real;','reg;','reg','rfloor;','rho;',
  96. 'rlm;','rsaquo;','rsquo;','sbquo;','scaron;','sdot;','sect;','sect','shy;',
  97. 'shy','sigma;','sigmaf;','sim;','spades;','sub;','sube;','sum;','sup1;',
  98. 'sup1','sup2;','sup2','sup3;','sup3','sup;','supe;','szlig;','szlig','tau;',
  99. 'there4;','theta;','thetasym;','thinsp;','thorn;','thorn','tilde;','times;',
  100. 'times','trade;','uArr;','uacute;','uacute','uarr;','ucirc;','ucirc',
  101. 'ugrave;','ugrave','uml;','uml','upsih;','upsilon;','uuml;','uuml','weierp;',
  102. 'xi;','yacute;','yacute','yen;','yen','yuml;','yuml','zeta;','zwj;','zwnj;');
  103. const PCDATA = 0;
  104. const RCDATA = 1;
  105. const CDATA = 2;
  106. const PLAINTEXT = 3;
  107. const DOCTYPE = 0;
  108. const STARTTAG = 1;
  109. const ENDTAG = 2;
  110. const COMMENT = 3;
  111. const CHARACTR = 4;
  112. const EOF = 5;
  113. public function __construct($data) {
  114. $data = str_replace("\r\n", "\n", $data);
  115. $data = str_replace("\r", null, $data);
  116. $this->data = $data;
  117. $this->char = -1;
  118. $this->EOF = strlen($data);
  119. $this->tree = new HTML5TreeConstructer;
  120. $this->content_model = self::PCDATA;
  121. $this->state = 'data';
  122. while($this->state !== null) {
  123. $this->{$this->state.'State'}();
  124. }
  125. }
  126. public function save() {
  127. return $this->tree->save();
  128. }
  129. private function char() {
  130. return ($this->char < $this->EOF)
  131. ? $this->data[$this->char]
  132. : false;
  133. }
  134. private function character($s, $l = 0) {
  135. if($s + $l < $this->EOF) {
  136. if($l === 0) {
  137. return $this->data[$s];
  138. } else {
  139. return substr($this->data, $s, $l);
  140. }
  141. }
  142. }
  143. private function characters($char_class, $start) {
  144. return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
  145. }
  146. private function dataState() {
  147. // Consume the next input character
  148. $this->char++;
  149. $char = $this->char();
  150. if($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
  151. /* U+0026 AMPERSAND (&)
  152. When the content model flag is set to one of the PCDATA or RCDATA
  153. states: switch to the entity data state. Otherwise: treat it as per
  154. the "anything else" entry below. */
  155. $this->state = 'entityData';
  156. } elseif($char === '-') {
  157. /* If the content model flag is set to either the RCDATA state or
  158. the CDATA state, and the escape flag is false, and there are at
  159. least three characters before this one in the input stream, and the
  160. last four characters in the input stream, including this one, are
  161. U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
  162. and U+002D HYPHEN-MINUS ("<!--"), then set the escape flag to true. */
  163. if(($this->content_model === self::RCDATA || $this->content_model ===
  164. self::CDATA) && $this->escape === false &&
  165. $this->char >= 3 && $this->character($this->char - 4, 4) === '<!--') {
  166. $this->escape = true;
  167. }
  168. /* In any case, emit the input character as a character token. Stay
  169. in the data state. */
  170. $this->emitToken(array(
  171. 'type' => self::CHARACTR,
  172. 'data' => $char
  173. ));
  174. /* U+003C LESS-THAN SIGN (<) */
  175. } elseif($char === '<' && ($this->content_model === self::PCDATA ||
  176. (($this->content_model === self::RCDATA ||
  177. $this->content_model === self::CDATA) && $this->escape === false))) {
  178. /* When the content model flag is set to the PCDATA state: switch
  179. to the tag open state.
  180. When the content model flag is set to either the RCDATA state or
  181. the CDATA state and the escape flag is false: switch to the tag
  182. open state.
  183. Otherwise: treat it as per the "anything else" entry below. */
  184. $this->state = 'tagOpen';
  185. /* U+003E GREATER-THAN SIGN (>) */
  186. } elseif($char === '>') {
  187. /* If the content model flag is set to either the RCDATA state or
  188. the CDATA state, and the escape flag is true, and the last three
  189. characters in the input stream including this one are U+002D
  190. HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"),
  191. set the escape flag to false. */
  192. if(($this->content_model === self::RCDATA ||
  193. $this->content_model === self::CDATA) && $this->escape === true &&
  194. $this->character($this->char, 3) === '-->') {
  195. $this->escape = false;
  196. }
  197. /* In any case, emit the input character as a character token.
  198. Stay in the data state. */
  199. $this->emitToken(array(
  200. 'type' => self::CHARACTR,
  201. 'data' => $char
  202. ));
  203. } elseif($this->char === $this->EOF) {
  204. /* EOF
  205. Emit an end-of-file token. */
  206. $this->EOF();
  207. } elseif($this->content_model === self::PLAINTEXT) {
  208. /* When the content model flag is set to the PLAINTEXT state
  209. THIS DIFFERS GREATLY FROM THE SPEC: Get the remaining characters of
  210. the text and emit it as a character token. */
  211. $this->emitToken(array(
  212. 'type' => self::CHARACTR,
  213. 'data' => substr($this->data, $this->char)
  214. ));
  215. $this->EOF();
  216. } else {
  217. /* Anything else
  218. THIS DIFFERS GREATLY FROM THE SPEC: Get as many character that
  219. otherwise would also be treated as a character token and emit it
  220. as a single character token. Stay in the data state. */
  221. $len = strcspn($this->data, '<&', $this->char);
  222. $char = substr($this->data, $this->char, $len);
  223. $this->char += $len - 1;
  224. $this->emitToken(array(
  225. 'type' => self::CHARACTR,
  226. 'data' => $char
  227. ));
  228. $this->state = 'data';
  229. }
  230. }
  231. private function entityDataState() {
  232. // Attempt to consume an entity.
  233. $entity = $this->entity();
  234. // If nothing is returned, emit a U+0026 AMPERSAND character token.
  235. // Otherwise, emit the character token that was returned.
  236. $char = (!$entity) ? '&' : $entity;
  237. $this->emitToken(array(
  238. 'type' => self::CHARACTR,
  239. 'data' => $char
  240. ));
  241. // Finally, switch to the data state.
  242. $this->state = 'data';
  243. }
  244. private function tagOpenState() {
  245. switch($this->content_model) {
  246. case self::RCDATA:
  247. case self::CDATA:
  248. /* If the next input character is a U+002F SOLIDUS (/) character,
  249. consume it and switch to the close tag open state. If the next
  250. input character is not a U+002F SOLIDUS (/) character, emit a
  251. U+003C LESS-THAN SIGN character token and switch to the data
  252. state to process the next input character. */
  253. if($this->character($this->char + 1) === '/') {
  254. $this->char++;
  255. $this->state = 'closeTagOpen';
  256. } else {
  257. $this->emitToken(array(
  258. 'type' => self::CHARACTR,
  259. 'data' => '<'
  260. ));
  261. $this->state = 'data';
  262. }
  263. break;
  264. case self::PCDATA:
  265. // If the content model flag is set to the PCDATA state
  266. // Consume the next input character:
  267. $this->char++;
  268. $char = $this->char();
  269. if($char === '!') {
  270. /* U+0021 EXCLAMATION MARK (!)
  271. Switch to the markup declaration open state. */
  272. $this->state = 'markupDeclarationOpen';
  273. } elseif($char === '/') {
  274. /* U+002F SOLIDUS (/)
  275. Switch to the close tag open state. */
  276. $this->state = 'closeTagOpen';
  277. } elseif(preg_match('/^[A-Za-z]$/', $char)) {
  278. /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
  279. Create a new start tag token, set its tag name to the lowercase
  280. version of the input character (add 0x0020 to the character's code
  281. point), then switch to the tag name state. (Don't emit the token
  282. yet; further details will be filled in before it is emitted.) */
  283. $this->token = array(
  284. 'name' => strtolower($char),
  285. 'type' => self::STARTTAG,
  286. 'attr' => array()
  287. );
  288. $this->state = 'tagName';
  289. } elseif($char === '>') {
  290. /* U+003E GREATER-THAN SIGN (>)
  291. Parse error. Emit a U+003C LESS-THAN SIGN character token and a
  292. U+003E GREATER-THAN SIGN character token. Switch to the data state. */
  293. $this->emitToken(array(
  294. 'type' => self::CHARACTR,
  295. 'data' => '<>'
  296. ));
  297. $this->state = 'data';
  298. } elseif($char === '?') {
  299. /* U+003F QUESTION MARK (?)
  300. Parse error. Switch to the bogus comment state. */
  301. $this->state = 'bogusComment';
  302. } else {
  303. /* Anything else
  304. Parse error. Emit a U+003C LESS-THAN SIGN character token and
  305. reconsume the current input character in the data state. */
  306. $this->emitToken(array(
  307. 'type' => self::CHARACTR,
  308. 'data' => '<'
  309. ));
  310. $this->char--;
  311. $this->state = 'data';
  312. }
  313. break;
  314. }
  315. }
  316. private function closeTagOpenState() {
  317. $next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
  318. $the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
  319. if(($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
  320. (!$the_same || ($the_same && (!preg_match('/[\t\n\x0b\x0c >\/]/',
  321. $this->character($this->char + 1 + strlen($next_node))) || $this->EOF === $this->char)))) {
  322. /* If the content model flag is set to the RCDATA or CDATA states then
  323. examine the next few characters. If they do not match the tag name of
  324. the last start tag token emitted (case insensitively), or if they do but
  325. they are not immediately followed by one of the following characters:
  326. * U+0009 CHARACTER TABULATION
  327. * U+000A LINE FEED (LF)
  328. * U+000B LINE TABULATION
  329. * U+000C FORM FEED (FF)
  330. * U+0020 SPACE
  331. * U+003E GREATER-THAN SIGN (>)
  332. * U+002F SOLIDUS (/)
  333. * EOF
  334. ...then there is a parse error. Emit a U+003C LESS-THAN SIGN character
  335. token, a U+002F SOLIDUS character token, and switch to the data state
  336. to process the next input character. */
  337. $this->emitToken(array(
  338. 'type' => self::CHARACTR,
  339. 'data' => '</'
  340. ));
  341. $this->state = 'data';
  342. } else {
  343. /* Otherwise, if the content model flag is set to the PCDATA state,
  344. or if the next few characters do match that tag name, consume the
  345. next input character: */
  346. $this->char++;
  347. $char = $this->char();
  348. if(preg_match('/^[A-Za-z]$/', $char)) {
  349. /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
  350. Create a new end tag token, set its tag name to the lowercase version
  351. of the input character (add 0x0020 to the character's code point), then
  352. switch to the tag name state. (Don't emit the token yet; further details
  353. will be filled in before it is emitted.) */
  354. $this->token = array(
  355. 'name' => strtolower($char),
  356. 'type' => self::ENDTAG
  357. );
  358. $this->state = 'tagName';
  359. } elseif($char === '>') {
  360. /* U+003E GREATER-THAN SIGN (>)
  361. Parse error. Switch to the data state. */
  362. $this->state = 'data';
  363. } elseif($this->char === $this->EOF) {
  364. /* EOF
  365. Parse error. Emit a U+003C LESS-THAN SIGN character token and a U+002F
  366. SOLIDUS character token. Reconsume the EOF character in the data state. */
  367. $this->emitToken(array(
  368. 'type' => self::CHARACTR,
  369. 'data' => '</'
  370. ));
  371. $this->char--;
  372. $this->state = 'data';
  373. } else {
  374. /* Parse error. Switch to the bogus comment state. */
  375. $this->state = 'bogusComment';
  376. }
  377. }
  378. }
  379. private function tagNameState() {
  380. // Consume the next input character:
  381. $this->char++;
  382. $char = $this->character($this->char);
  383. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  384. /* U+0009 CHARACTER TABULATION
  385. U+000A LINE FEED (LF)
  386. U+000B LINE TABULATION
  387. U+000C FORM FEED (FF)
  388. U+0020 SPACE
  389. Switch to the before attribute name state. */
  390. $this->state = 'beforeAttributeName';
  391. } elseif($char === '>') {
  392. /* U+003E GREATER-THAN SIGN (>)
  393. Emit the current tag token. Switch to the data state. */
  394. $this->emitToken($this->token);
  395. $this->state = 'data';
  396. } elseif($this->char === $this->EOF) {
  397. /* EOF
  398. Parse error. Emit the current tag token. Reconsume the EOF
  399. character in the data state. */
  400. $this->emitToken($this->token);
  401. $this->char--;
  402. $this->state = 'data';
  403. } elseif($char === '/') {
  404. /* U+002F SOLIDUS (/)
  405. Parse error unless this is a permitted slash. Switch to the before
  406. attribute name state. */
  407. $this->state = 'beforeAttributeName';
  408. } else {
  409. /* Anything else
  410. Append the current input character to the current tag token's tag name.
  411. Stay in the tag name state. */
  412. $this->token['name'] .= strtolower($char);
  413. $this->state = 'tagName';
  414. }
  415. }
  416. private function beforeAttributeNameState() {
  417. // Consume the next input character:
  418. $this->char++;
  419. $char = $this->character($this->char);
  420. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  421. /* U+0009 CHARACTER TABULATION
  422. U+000A LINE FEED (LF)
  423. U+000B LINE TABULATION
  424. U+000C FORM FEED (FF)
  425. U+0020 SPACE
  426. Stay in the before attribute name state. */
  427. $this->state = 'beforeAttributeName';
  428. } elseif($char === '>') {
  429. /* U+003E GREATER-THAN SIGN (>)
  430. Emit the current tag token. Switch to the data state. */
  431. $this->emitToken($this->token);
  432. $this->state = 'data';
  433. } elseif($char === '/') {
  434. /* U+002F SOLIDUS (/)
  435. Parse error unless this is a permitted slash. Stay in the before
  436. attribute name state. */
  437. $this->state = 'beforeAttributeName';
  438. } elseif($this->char === $this->EOF) {
  439. /* EOF
  440. Parse error. Emit the current tag token. Reconsume the EOF
  441. character in the data state. */
  442. $this->emitToken($this->token);
  443. $this->char--;
  444. $this->state = 'data';
  445. } else {
  446. /* Anything else
  447. Start a new attribute in the current tag token. Set that attribute's
  448. name to the current input character, and its value to the empty string.
  449. Switch to the attribute name state. */
  450. $this->token['attr'][] = array(
  451. 'name' => strtolower($char),
  452. 'value' => null
  453. );
  454. $this->state = 'attributeName';
  455. }
  456. }
  457. private function attributeNameState() {
  458. // Consume the next input character:
  459. $this->char++;
  460. $char = $this->character($this->char);
  461. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  462. /* U+0009 CHARACTER TABULATION
  463. U+000A LINE FEED (LF)
  464. U+000B LINE TABULATION
  465. U+000C FORM FEED (FF)
  466. U+0020 SPACE
  467. Stay in the before attribute name state. */
  468. $this->state = 'afterAttributeName';
  469. } elseif($char === '=') {
  470. /* U+003D EQUALS SIGN (=)
  471. Switch to the before attribute value state. */
  472. $this->state = 'beforeAttributeValue';
  473. } elseif($char === '>') {
  474. /* U+003E GREATER-THAN SIGN (>)
  475. Emit the current tag token. Switch to the data state. */
  476. $this->emitToken($this->token);
  477. $this->state = 'data';
  478. } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
  479. /* U+002F SOLIDUS (/)
  480. Parse error unless this is a permitted slash. Switch to the before
  481. attribute name state. */
  482. $this->state = 'beforeAttributeName';
  483. } elseif($this->char === $this->EOF) {
  484. /* EOF
  485. Parse error. Emit the current tag token. Reconsume the EOF
  486. character in the data state. */
  487. $this->emitToken($this->token);
  488. $this->char--;
  489. $this->state = 'data';
  490. } else {
  491. /* Anything else
  492. Append the current input character to the current attribute's name.
  493. Stay in the attribute name state. */
  494. $last = count($this->token['attr']) - 1;
  495. $this->token['attr'][$last]['name'] .= strtolower($char);
  496. $this->state = 'attributeName';
  497. }
  498. }
  499. private function afterAttributeNameState() {
  500. // Consume the next input character:
  501. $this->char++;
  502. $char = $this->character($this->char);
  503. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  504. /* U+0009 CHARACTER TABULATION
  505. U+000A LINE FEED (LF)
  506. U+000B LINE TABULATION
  507. U+000C FORM FEED (FF)
  508. U+0020 SPACE
  509. Stay in the after attribute name state. */
  510. $this->state = 'afterAttributeName';
  511. } elseif($char === '=') {
  512. /* U+003D EQUALS SIGN (=)
  513. Switch to the before attribute value state. */
  514. $this->state = 'beforeAttributeValue';
  515. } elseif($char === '>') {
  516. /* U+003E GREATER-THAN SIGN (>)
  517. Emit the current tag token. Switch to the data state. */
  518. $this->emitToken($this->token);
  519. $this->state = 'data';
  520. } elseif($char === '/' && $this->character($this->char + 1) !== '>') {
  521. /* U+002F SOLIDUS (/)
  522. Parse error unless this is a permitted slash. Switch to the
  523. before attribute name state. */
  524. $this->state = 'beforeAttributeName';
  525. } elseif($this->char === $this->EOF) {
  526. /* EOF
  527. Parse error. Emit the current tag token. Reconsume the EOF
  528. character in the data state. */
  529. $this->emitToken($this->token);
  530. $this->char--;
  531. $this->state = 'data';
  532. } else {
  533. /* Anything else
  534. Start a new attribute in the current tag token. Set that attribute's
  535. name to the current input character, and its value to the empty string.
  536. Switch to the attribute name state. */
  537. $this->token['attr'][] = array(
  538. 'name' => strtolower($char),
  539. 'value' => null
  540. );
  541. $this->state = 'attributeName';
  542. }
  543. }
  544. private function beforeAttributeValueState() {
  545. // Consume the next input character:
  546. $this->char++;
  547. $char = $this->character($this->char);
  548. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  549. /* U+0009 CHARACTER TABULATION
  550. U+000A LINE FEED (LF)
  551. U+000B LINE TABULATION
  552. U+000C FORM FEED (FF)
  553. U+0020 SPACE
  554. Stay in the before attribute value state. */
  555. $this->state = 'beforeAttributeValue';
  556. } elseif($char === '"') {
  557. /* U+0022 QUOTATION MARK (")
  558. Switch to the attribute value (double-quoted) state. */
  559. $this->state = 'attributeValueDoubleQuoted';
  560. } elseif($char === '&') {
  561. /* U+0026 AMPERSAND (&)
  562. Switch to the attribute value (unquoted) state and reconsume
  563. this input character. */
  564. $this->char--;
  565. $this->state = 'attributeValueUnquoted';
  566. } elseif($char === '\'') {
  567. /* U+0027 APOSTROPHE (')
  568. Switch to the attribute value (single-quoted) state. */
  569. $this->state = 'attributeValueSingleQuoted';
  570. } elseif($char === '>') {
  571. /* U+003E GREATER-THAN SIGN (>)
  572. Emit the current tag token. Switch to the data state. */
  573. $this->emitToken($this->token);
  574. $this->state = 'data';
  575. } else {
  576. /* Anything else
  577. Append the current input character to the current attribute's value.
  578. Switch to the attribute value (unquoted) state. */
  579. $last = count($this->token['attr']) - 1;
  580. $this->token['attr'][$last]['value'] .= $char;
  581. $this->state = 'attributeValueUnquoted';
  582. }
  583. }
  584. private function attributeValueDoubleQuotedState() {
  585. // Consume the next input character:
  586. $this->char++;
  587. $char = $this->character($this->char);
  588. if($char === '"') {
  589. /* U+0022 QUOTATION MARK (")
  590. Switch to the before attribute name state. */
  591. $this->state = 'beforeAttributeName';
  592. } elseif($char === '&') {
  593. /* U+0026 AMPERSAND (&)
  594. Switch to the entity in attribute value state. */
  595. $this->entityInAttributeValueState('double');
  596. } elseif($this->char === $this->EOF) {
  597. /* EOF
  598. Parse error. Emit the current tag token. Reconsume the character
  599. in the data state. */
  600. $this->emitToken($this->token);
  601. $this->char--;
  602. $this->state = 'data';
  603. } else {
  604. /* Anything else
  605. Append the current input character to the current attribute's value.
  606. Stay in the attribute value (double-quoted) state. */
  607. $last = count($this->token['attr']) - 1;
  608. $this->token['attr'][$last]['value'] .= $char;
  609. $this->state = 'attributeValueDoubleQuoted';
  610. }
  611. }
  612. private function attributeValueSingleQuotedState() {
  613. // Consume the next input character:
  614. $this->char++;
  615. $char = $this->character($this->char);
  616. if($char === '\'') {
  617. /* U+0022 QUOTATION MARK (')
  618. Switch to the before attribute name state. */
  619. $this->state = 'beforeAttributeName';
  620. } elseif($char === '&') {
  621. /* U+0026 AMPERSAND (&)
  622. Switch to the entity in attribute value state. */
  623. $this->entityInAttributeValueState('single');
  624. } elseif($this->char === $this->EOF) {
  625. /* EOF
  626. Parse error. Emit the current tag token. Reconsume the character
  627. in the data state. */
  628. $this->emitToken($this->token);
  629. $this->char--;
  630. $this->state = 'data';
  631. } else {
  632. /* Anything else
  633. Append the current input character to the current attribute's value.
  634. Stay in the attribute value (single-quoted) state. */
  635. $last = count($this->token['attr']) - 1;
  636. $this->token['attr'][$last]['value'] .= $char;
  637. $this->state = 'attributeValueSingleQuoted';
  638. }
  639. }
  640. private function attributeValueUnquotedState() {
  641. // Consume the next input character:
  642. $this->char++;
  643. $char = $this->character($this->char);
  644. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  645. /* U+0009 CHARACTER TABULATION
  646. U+000A LINE FEED (LF)
  647. U+000B LINE TABULATION
  648. U+000C FORM FEED (FF)
  649. U+0020 SPACE
  650. Switch to the before attribute name state. */
  651. $this->state = 'beforeAttributeName';
  652. } elseif($char === '&') {
  653. /* U+0026 AMPERSAND (&)
  654. Switch to the entity in attribute value state. */
  655. $this->entityInAttributeValueState();
  656. } elseif($char === '>') {
  657. /* U+003E GREATER-THAN SIGN (>)
  658. Emit the current tag token. Switch to the data state. */
  659. $this->emitToken($this->token);
  660. $this->state = 'data';
  661. } else {
  662. /* Anything else
  663. Append the current input character to the current attribute's value.
  664. Stay in the attribute value (unquoted) state. */
  665. $last = count($this->token['attr']) - 1;
  666. $this->token['attr'][$last]['value'] .= $char;
  667. $this->state = 'attributeValueUnquoted';
  668. }
  669. }
  670. private function entityInAttributeValueState() {
  671. // Attempt to consume an entity.
  672. $entity = $this->entity();
  673. // If nothing is returned, append a U+0026 AMPERSAND character to the
  674. // current attribute's value. Otherwise, emit the character token that
  675. // was returned.
  676. $char = (!$entity)
  677. ? '&'
  678. : $entity;
  679. $last = count($this->token['attr']) - 1;
  680. $this->token['attr'][$last]['value'] .= $char;
  681. }
  682. private function bogusCommentState() {
  683. /* Consume every character up to the first U+003E GREATER-THAN SIGN
  684. character (>) or the end of the file (EOF), whichever comes first. Emit
  685. a comment token whose data is the concatenation of all the characters
  686. starting from and including the character that caused the state machine
  687. to switch into the bogus comment state, up to and including the last
  688. consumed character before the U+003E character, if any, or up to the
  689. end of the file otherwise. (If the comment was started by the end of
  690. the file (EOF), the token is empty.) */
  691. $data = $this->characters('^>', $this->char);
  692. $this->emitToken(array(
  693. 'data' => $data,
  694. 'type' => self::COMMENT
  695. ));
  696. $this->char += strlen($data);
  697. /* Switch to the data state. */
  698. $this->state = 'data';
  699. /* If the end of the file was reached, reconsume the EOF character. */
  700. if($this->char === $this->EOF) {
  701. $this->char = $this->EOF - 1;
  702. }
  703. }
  704. private function markupDeclarationOpenState() {
  705. /* If the next two characters are both U+002D HYPHEN-MINUS (-)
  706. characters, consume those two characters, create a comment token whose
  707. data is the empty string, and switch to the comment state. */
  708. if($this->character($this->char + 1, 2) === '--') {
  709. $this->char += 2;
  710. $this->state = 'comment';
  711. $this->token = array(
  712. 'data' => null,
  713. 'type' => self::COMMENT
  714. );
  715. /* Otherwise if the next seven chacacters are a case-insensitive match
  716. for the word "DOCTYPE", then consume those characters and switch to the
  717. DOCTYPE state. */
  718. } elseif(strtolower($this->character($this->char + 1, 7)) === 'doctype') {
  719. $this->char += 7;
  720. $this->state = 'doctype';
  721. /* Otherwise, is is a parse error. Switch to the bogus comment state.
  722. The next character that is consumed, if any, is the first character
  723. that will be in the comment. */
  724. } else {
  725. $this->char++;
  726. $this->state = 'bogusComment';
  727. }
  728. }
  729. private function commentState() {
  730. /* Consume the next input character: */
  731. $this->char++;
  732. $char = $this->char();
  733. /* U+002D HYPHEN-MINUS (-) */
  734. if($char === '-') {
  735. /* Switch to the comment dash state */
  736. $this->state = 'commentDash';
  737. /* EOF */
  738. } elseif($this->char === $this->EOF) {
  739. /* Parse error. Emit the comment token. Reconsume the EOF character
  740. in the data state. */
  741. $this->emitToken($this->token);
  742. $this->char--;
  743. $this->state = 'data';
  744. /* Anything else */
  745. } else {
  746. /* Append the input character to the comment token's data. Stay in
  747. the comment state. */
  748. $this->token['data'] .= $char;
  749. }
  750. }
  751. private function commentDashState() {
  752. /* Consume the next input character: */
  753. $this->char++;
  754. $char = $this->char();
  755. /* U+002D HYPHEN-MINUS (-) */
  756. if($char === '-') {
  757. /* Switch to the comment end state */
  758. $this->state = 'commentEnd';
  759. /* EOF */
  760. } elseif($this->char === $this->EOF) {
  761. /* Parse error. Emit the comment token. Reconsume the EOF character
  762. in the data state. */
  763. $this->emitToken($this->token);
  764. $this->char--;
  765. $this->state = 'data';
  766. /* Anything else */
  767. } else {
  768. /* Append a U+002D HYPHEN-MINUS (-) character and the input
  769. character to the comment token's data. Switch to the comment state. */
  770. $this->token['data'] .= '-'.$char;
  771. $this->state = 'comment';
  772. }
  773. }
  774. private function commentEndState() {
  775. /* Consume the next input character: */
  776. $this->char++;
  777. $char = $this->char();
  778. if($char === '>') {
  779. $this->emitToken($this->token);
  780. $this->state = 'data';
  781. } elseif($char === '-') {
  782. $this->token['data'] .= '-';
  783. } elseif($this->char === $this->EOF) {
  784. $this->emitToken($this->token);
  785. $this->char--;
  786. $this->state = 'data';
  787. } else {
  788. $this->token['data'] .= '--'.$char;
  789. $this->state = 'comment';
  790. }
  791. }
  792. private function doctypeState() {
  793. /* Consume the next input character: */
  794. $this->char++;
  795. $char = $this->char();
  796. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  797. $this->state = 'beforeDoctypeName';
  798. } else {
  799. $this->char--;
  800. $this->state = 'beforeDoctypeName';
  801. }
  802. }
  803. private function beforeDoctypeNameState() {
  804. /* Consume the next input character: */
  805. $this->char++;
  806. $char = $this->char();
  807. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  808. // Stay in the before DOCTYPE name state.
  809. } elseif(preg_match('/^[a-z]$/', $char)) {
  810. $this->token = array(
  811. 'name' => strtoupper($char),
  812. 'type' => self::DOCTYPE,
  813. 'error' => true
  814. );
  815. $this->state = 'doctypeName';
  816. } elseif($char === '>') {
  817. $this->emitToken(array(
  818. 'name' => null,
  819. 'type' => self::DOCTYPE,
  820. 'error' => true
  821. ));
  822. $this->state = 'data';
  823. } elseif($this->char === $this->EOF) {
  824. $this->emitToken(array(
  825. 'name' => null,
  826. 'type' => self::DOCTYPE,
  827. 'error' => true
  828. ));
  829. $this->char--;
  830. $this->state = 'data';
  831. } else {
  832. $this->token = array(
  833. 'name' => $char,
  834. 'type' => self::DOCTYPE,
  835. 'error' => true
  836. );
  837. $this->state = 'doctypeName';
  838. }
  839. }
  840. private function doctypeNameState() {
  841. /* Consume the next input character: */
  842. $this->char++;
  843. $char = $this->char();
  844. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  845. $this->state = 'AfterDoctypeName';
  846. } elseif($char === '>') {
  847. $this->emitToken($this->token);
  848. $this->state = 'data';
  849. } elseif(preg_match('/^[a-z]$/', $char)) {
  850. $this->token['name'] .= strtoupper($char);
  851. } elseif($this->char === $this->EOF) {
  852. $this->emitToken($this->token);
  853. $this->char--;
  854. $this->state = 'data';
  855. } else {
  856. $this->token['name'] .= $char;
  857. }
  858. $this->token['error'] = ($this->token['name'] === 'HTML')
  859. ? false
  860. : true;
  861. }
  862. private function afterDoctypeNameState() {
  863. /* Consume the next input character: */
  864. $this->char++;
  865. $char = $this->char();
  866. if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
  867. // Stay in the DOCTYPE name state.
  868. } elseif($char === '>') {
  869. $this->emitToken($this->token);
  870. $this->state = 'data';
  871. } elseif($this->char === $this->EOF) {
  872. $this->emitToken($this->token);
  873. $this->char--;
  874. $this->state = 'data';
  875. } else {
  876. $this->token['error'] = true;
  877. $this->state = 'bogusDoctype';
  878. }
  879. }
  880. private function bogusDoctypeState() {
  881. /* Consume the next input character: */
  882. $this->char++;
  883. $char = $this->char();
  884. if($char === '>') {
  885. $this->emitToken($this->token);
  886. $this->state = 'data';
  887. } elseif($this->char === $this->EOF) {
  888. $this->emitToken($this->token);
  889. $this->char--;
  890. $this->state = 'data';
  891. } else {
  892. // Stay in the bogus DOCTYPE state.
  893. }
  894. }
  895. private function entity() {
  896. $start = $this->char;
  897. // This section defines how to consume an entity. This definition is
  898. // used when parsing entities in text and in attributes.
  899. // The behaviour depends on the identity of the next character (the
  900. // one immediately after the U+0026 AMPERSAND character):
  901. switch($this->character($this->char + 1)) {
  902. // U+0023 NUMBER SIGN (#)
  903. case '#':
  904. // The behaviour further depends on the character after the
  905. // U+0023 NUMBER SIGN:
  906. switch($this->character($this->char + 1)) {
  907. // U+0078 LATIN SMALL LETTER X
  908. // U+0058 LATIN CAPITAL LETTER X
  909. case 'x':
  910. case 'X':
  911. // Follow the steps below, but using the range of
  912. // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
  913. // NINE, U+0061 LATIN SMALL LETTER A through to U+0066
  914. // LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
  915. // A, through to U+0046 LATIN CAPITAL LETTER F (in other
  916. // words, 0-9, A-F, a-f).
  917. $char = 1;
  918. $char_class = '0-9A-Fa-f';
  919. break;
  920. // Anything else
  921. default:
  922. // Follow the steps below, but using the range of
  923. // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
  924. // NINE (i.e. just 0-9).
  925. $char = 0;
  926. $char_class = '0-9';
  927. break;
  928. }
  929. // Consume as many characters as match the range of characters
  930. // given above.
  931. $this->char++;
  932. $e_name = $this->characters($char_class, $this->char + $char + 1);
  933. $entity = $this->character($start, $this->char);
  934. $cond = strlen($e_name) > 0;
  935. // The rest of the parsing happens bellow.
  936. break;
  937. // Anything else
  938. default:
  939. // Consume the maximum number of characters possible, with the
  940. // consumed characters case-sensitively matching one of the
  941. // identifiers in the first column of the entities table.
  942. $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
  943. $len = strlen($e_name);
  944. for($c = 1; $c <= $len; $c++) {
  945. $id = substr($e_name, 0, $c);
  946. $this->char++;
  947. if(in_array($id, $this->entities)) {
  948. if ($e_name[$c-1] !== ';') {
  949. if ($c < $len && $e_name[$c] == ';') {
  950. $this->char++; // consume extra semicolon
  951. }
  952. }
  953. $entity = $id;
  954. break;
  955. }
  956. }
  957. $cond = isset($entity);
  958. // The rest of the parsing happens bellow.
  959. break;
  960. }
  961. if(!$cond) {
  962. // If no match can be made, then this is a parse error. No
  963. // characters are consumed, and nothing is returned.
  964. $this->char = $start;
  965. return false;
  966. }
  967. // Return a character token for the character corresponding to the
  968. // entity name (as given by the second column of the entities table).
  969. return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8');
  970. }
  971. private function emitToken($token) {
  972. $emit = $this->tree->emitToken($token);
  973. if(is_int($emit)) {
  974. $this->content_model = $emit;
  975. } elseif($token['type'] === self::ENDTAG) {
  976. $this->content_model = self::PCDATA;
  977. }
  978. }
  979. private function EOF() {
  980. $this->state = null;
  981. $this->tree->emitToken(array(
  982. 'type' => self::EOF
  983. ));
  984. }
  985. }
  986. class HTML5TreeConstructer {
  987. public $stack = array();
  988. private $phase;
  989. private $mode;
  990. private $dom;
  991. private $foster_parent = null;
  992. private $a_formatting = array();
  993. private $head_pointer = null;
  994. private $form_pointer = null;
  995. private $scoping = array('button','caption','html','marquee','object','table','td','th');
  996. private $formatting = array('a','b','big','em','font','i','nobr','s','small','strike','strong','tt','u');
  997. private $special = array('address','area','base','basefont','bgsound',
  998. 'blockquote','body','br','center','col','colgroup','dd','dir','div','dl',
  999. 'dt','embed','fieldset','form','frame','frameset','h1','h2','h3','h4','h5',
  1000. 'h6','head','hr','iframe','image','img','input','isindex','li','link',
  1001. 'listing','menu','meta','noembed','noframes','noscript','ol','optgroup',
  1002. 'option','p','param','plaintext','pre','script','select','spacer','style',
  1003. 'tbody','textarea','tfoot','thead','title','tr','ul','wbr');
  1004. // The different phases.
  1005. const INIT_PHASE = 0;
  1006. const ROOT_PHASE = 1;
  1007. const MAIN_PHASE = 2;
  1008. const END_PHASE = 3;
  1009. // The different insertion modes for the main phase.
  1010. const BEFOR_HEAD = 0;
  1011. const IN_HEAD = 1;
  1012. const AFTER_HEAD = 2;
  1013. const IN_BODY = 3;
  1014. const IN_TABLE = 4;
  1015. const IN_CAPTION = 5;
  1016. const IN_CGROUP = 6;
  1017. const IN_TBODY = 7;
  1018. const IN_ROW = 8;
  1019. const IN_CELL = 9;
  1020. const IN_SELECT = 10;
  1021. const AFTER_BODY = 11;
  1022. const IN_FRAME = 12;
  1023. const AFTR_FRAME = 13;
  1024. // The different types of elements.
  1025. const SPECIAL = 0;
  1026. const SCOPING = 1;
  1027. const FORMATTING = 2;
  1028. const PHRASING = 3;
  1029. const MARKER = 0;
  1030. public function __construct() {
  1031. $this->phase = self::INIT_PHASE;
  1032. $this->mode = self::BEFOR_HEAD;
  1033. $this->dom = new DOMDocument;
  1034. $this->dom->encoding = 'UTF-8';
  1035. $this->dom->preserveWhiteSpace = true;
  1036. $this->dom->substituteEntities = true;
  1037. $this->dom->strictErrorChecking = false;
  1038. }
  1039. // Process tag tokens
  1040. public function emitToken($token) {
  1041. switch($this->phase) {
  1042. case self::INIT_PHASE: return $this->initPhase($token); break;
  1043. case self::ROOT_PHASE: return $this->rootElementPhase($token); break;
  1044. case self::MAIN_PHASE: return $this->mainPhase($token); break;
  1045. case self::END_PHASE : return $this->trailingEndPhase($token); break;
  1046. }
  1047. }
  1048. private function initPhase($token) {
  1049. /* Initially, the tree construction stage must handle each token
  1050. emitted from the tokenisation stage as follows: */
  1051. /* A DOCTYPE token that is marked as being in error
  1052. A comment token
  1053. A start tag token
  1054. An end tag token
  1055. A character token that is not one of one of U+0009 CHARACTER TABULATION,
  1056. U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  1057. or U+0020 SPACE
  1058. An end-of-file token */
  1059. if((isset($token['error']) && $token['error']) ||
  1060. $token['type'] === HTML5::COMMENT ||
  1061. $token['type'] === HTML5::STARTTAG ||
  1062. $token['type'] === HTML5::ENDTAG ||
  1063. $token['type'] === HTML5::EOF ||
  1064. ($token['type'] === HTML5::CHARACTR && isset($token['data']) &&
  1065. !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']))) {
  1066. /* This specification does not define how to handle this case. In
  1067. particular, user agents may ignore the entirety of this specification
  1068. altogether for such documents, and instead invoke special parse modes
  1069. with a greater emphasis on backwards compatibility. */
  1070. $this->phase = self::ROOT_PHASE;
  1071. return $this->rootElementPhase($token);
  1072. /* A DOCTYPE token marked as being correct */
  1073. } elseif(isset($token['error']) && !$token['error']) {
  1074. /* Append a DocumentType node to the Document node, with the name
  1075. attribute set to the name given in the DOCTYPE token (which will be
  1076. "HTML"), and the other attributes specific to DocumentType objects
  1077. set to null, empty lists, or the empty string as appropriate. */
  1078. $doctype = new DOMDocumentType(null, null, 'HTML');
  1079. /* Then, switch to the root element phase of the tree construction
  1080. stage. */
  1081. $this->phase = self::ROOT_PHASE;
  1082. /* A character token that is one of one of U+0009 CHARACTER TABULATION,
  1083. U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  1084. or U+0020 SPACE */
  1085. } elseif(isset($token['data']) && preg_match('/^[\t\n\x0b\x0c ]+$/',
  1086. $token['data'])) {
  1087. /* Append that character to the Document node. */
  1088. $text = $this->dom->createTextNode($token['data']);
  1089. $this->dom->appendChild($text);
  1090. }
  1091. }
  1092. private function rootElementPhase($token) {
  1093. /* After the initial phase, as each token is emitted from the tokenisation
  1094. stage, it must be processed as described in this section. */
  1095. /* A DOCTYPE token */
  1096. if($token['type'] === HTML5::DOCTYPE) {
  1097. // Parse error. Ignore the token.
  1098. /* A comment token */
  1099. } elseif($token['type'] === HTML5::COMMENT) {
  1100. /* Append a Comment node to the Document object with the data
  1101. attribute set to the data given in the comment token. */
  1102. $comment = $this->dom->createComment($token['data']);
  1103. $this->dom->appendChild($comment);
  1104. /* A character token that is one of one of U+0009 CHARACTER TABULATION,
  1105. U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
  1106. or U+0020 SPACE */
  1107. } elseif($token['type'] === HTML5::CHARACTR &&
  1108. preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) {
  1109. /* Append th…

Large files files are truncated, but you can click here to view the full file