StringImplicitBackslashesFixerTest.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\StringNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Filippo Tessarotto <zoeslam@gmail.com>
  16. * @author Michael Vorisek <https://github.com/mvorisek>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\StringNotation\StringImplicitBackslashesFixer
  21. *
  22. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\StringNotation\StringImplicitBackslashesFixer>
  23. *
  24. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\StringNotation\StringImplicitBackslashesFixer
  25. */
  26. final class StringImplicitBackslashesFixerTest extends AbstractFixerTestCase
  27. {
  28. /**
  29. * @param _AutogeneratedInputConfiguration $configuration
  30. *
  31. * @dataProvider provideFixCases
  32. */
  33. public function testFix(string $expected, ?string $input = null, array $configuration = []): void
  34. {
  35. $this->fixer->configure($configuration);
  36. $this->doTest($expected, $input);
  37. }
  38. /**
  39. * @return iterable<int|string, array{string, 1?: ?string, 2?: array<string, mixed>}>
  40. */
  41. public static function provideFixCases(): iterable
  42. {
  43. yield [
  44. <<<'EOD'
  45. <?php $var = 'String (\\\'\r\n\x0\) for My\Prefix\\';
  46. EOD,
  47. ];
  48. yield [
  49. <<<'EOD'
  50. <?php $var = 'String (\\\'\\r\\n\\x0\\) for My\\Prefix\\';
  51. EOD,
  52. <<<'EOD'
  53. <?php $var = 'String (\\\'\r\n\x0\) for My\Prefix\\';
  54. EOD,
  55. ['single_quoted' => 'escape'],
  56. ];
  57. yield [
  58. <<<'EOD'
  59. <?php
  60. $var = "\\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z";
  61. $var = "\\a\\b\\c\\d\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\\s\\w\\y\\z \\' \\8\\9 \\xZ \\u";
  62. $var = "$foo \\A \\a \\' \\8\\9 \\xZ \\u ${bar}";
  63. $var = <<<HEREDOC
  64. \\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z
  65. \\a\\b\\c\\d\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\\s\\w\\y\\z
  66. \\"
  67. \\'
  68. \\8\\9
  69. \\xZ
  70. \\u
  71. HEREDOC;
  72. $var = <<<HEREDOC
  73. $foo \\A \\a \\" \\' \\8\\9 \\xZ \\u ${bar}
  74. HEREDOC;
  75. $var = <<<'NOWDOC'
  76. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  77. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  78. \'
  79. \8\9
  80. \xZ
  81. \u
  82. NOWDOC;
  83. EOD,
  84. <<<'EOD'
  85. <?php
  86. $var = "\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z";
  87. $var = "\a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z \' \8\9 \xZ \u";
  88. $var = "$foo \A \a \' \8\9 \xZ \u ${bar}";
  89. $var = <<<HEREDOC
  90. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  91. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  92. \"
  93. \'
  94. \8\9
  95. \xZ
  96. \u
  97. HEREDOC;
  98. $var = <<<HEREDOC
  99. $foo \A \a \" \' \8\9 \xZ \u ${bar}
  100. HEREDOC;
  101. $var = <<<'NOWDOC'
  102. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  103. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  104. \'
  105. \8\9
  106. \xZ
  107. \u
  108. NOWDOC;
  109. EOD,
  110. ];
  111. yield [
  112. <<<'EOD'
  113. <?php
  114. $var = "\e\f\n\r\t\v \\ \$ \"";
  115. $var = "$foo \e\f\n\r\t\v \\ \$ \" ${bar}";
  116. $var = <<<HEREDOC
  117. \e\f\n\r\t\v \\ \$
  118. HEREDOC;
  119. $var = <<<HEREDOC
  120. $foo \e\f\n\r\t\v \\ \$ ${bar}
  121. HEREDOC;
  122. EOD,
  123. ];
  124. yield [
  125. <<<'EOD'
  126. <?php
  127. $var = "\0 \00 \000 \0000 \00000";
  128. $var = "$foo \0 \00 \000 \0000 \00000 ${bar}";
  129. $var = <<<HEREDOC
  130. \0 \00 \000 \0000 \00000
  131. HEREDOC;
  132. $var = <<<HEREDOC
  133. $foo \0 \00 \000 \0000 \00000 ${bar}
  134. HEREDOC;
  135. EOD,
  136. ];
  137. yield [
  138. <<<'EOD'
  139. <?php
  140. $var = "\xA \x99 \u{0}";
  141. $var = "$foo \xA \x99 \u{0} ${bar}";
  142. $var = <<<HEREDOC
  143. \xA \x99 \u{0}
  144. HEREDOC;
  145. $var = <<<HEREDOC
  146. $foo \xA \x99 \u{0} ${bar}
  147. HEREDOC;
  148. EOD,
  149. ];
  150. yield [
  151. <<<'EOD'
  152. <?php
  153. $var = 'backslash \ not escaped';
  154. $var = 'code coverage';
  155. $var = "backslash \\ already escaped";
  156. $var = "code coverage";
  157. $var = <<<HEREDOC
  158. backslash \\ already escaped
  159. HEREDOC;
  160. $var = <<<HEREDOC
  161. code coverage
  162. HEREDOC;
  163. $var = <<<'NOWDOC'
  164. backslash \\ already escaped
  165. NOWDOC;
  166. $var = <<<'NOWDOC'
  167. code coverage
  168. NOWDOC;
  169. EOD,
  170. ];
  171. yield [
  172. <<<'EOD'
  173. <?php
  174. $var = "\A\a \' \8\9 \xZ \u";
  175. $var = "$foo \A\a \' \8\9 \xZ \u ${bar}";
  176. EOD,
  177. null,
  178. ['double_quoted' => 'unescape'],
  179. ];
  180. yield [
  181. <<<'EOD'
  182. <?php
  183. $var = <<<HEREDOC
  184. \A\Z
  185. \a\z
  186. \'
  187. \8\9
  188. \xZ
  189. \u
  190. HEREDOC;
  191. $var = <<<HEREDOC
  192. $foo
  193. \A\Z
  194. \a\z
  195. \'
  196. \8\9
  197. \xZ
  198. \u
  199. ${bar}
  200. HEREDOC;
  201. EOD,
  202. null,
  203. ['heredoc' => 'unescape'],
  204. ];
  205. yield [
  206. <<<'EOD'
  207. <?php $var = b'String (\\\'\r\n\x0) for My\Prefix\\';
  208. EOD,
  209. ];
  210. yield [
  211. <<<'EOD'
  212. <?php $var = b'String (\\\'\\r\\n\\x0) for My\\Prefix\\';
  213. EOD,
  214. <<<'EOD'
  215. <?php $var = b'String (\\\'\r\n\x0) for My\Prefix\\';
  216. EOD,
  217. ['single_quoted' => 'escape'],
  218. ];
  219. yield [
  220. <<<'EOD'
  221. <?php
  222. $var = b"\\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z";
  223. $var = b"\\a\\b\\c\\d\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\\s\\w\\y\\z \\' \\8\\9 \\xZ \\u";
  224. $var = b"$foo \\A \\a \\' \\8\\9 \\xZ \\u ${bar}";
  225. $var = b<<<HEREDOC
  226. \\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z
  227. \\a\\b\\c\\d\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\\s\\w\\y\\z
  228. \\"
  229. \\'
  230. \\8\\9
  231. \\xZ
  232. \\u
  233. HEREDOC;
  234. $var = b<<<HEREDOC
  235. $foo \\A \\a \\" \\' \\8\\9 \\xZ \\u ${bar}
  236. HEREDOC;
  237. $var = b<<<'NOWDOC'
  238. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  239. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  240. \'
  241. \8\9
  242. \xZ
  243. \u
  244. NOWDOC;
  245. EOD,
  246. <<<'EOD'
  247. <?php
  248. $var = b"\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z";
  249. $var = b"\a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z \' \8\9 \xZ \u";
  250. $var = b"$foo \A \a \' \8\9 \xZ \u ${bar}";
  251. $var = b<<<HEREDOC
  252. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  253. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  254. \"
  255. \'
  256. \8\9
  257. \xZ
  258. \u
  259. HEREDOC;
  260. $var = b<<<HEREDOC
  261. $foo \A \a \" \' \8\9 \xZ \u ${bar}
  262. HEREDOC;
  263. $var = b<<<'NOWDOC'
  264. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  265. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  266. \'
  267. \8\9
  268. \xZ
  269. \u
  270. NOWDOC;
  271. EOD,
  272. ];
  273. yield [
  274. <<<'EOD'
  275. <?php
  276. $var = b"\e\f\n\r\t\v \\ \$ \"";
  277. $var = b"$foo \e\f\n\r\t\v \\ \$ \" ${bar}";
  278. $var = b<<<HEREDOC
  279. \e\f\n\r\t\v \\ \$
  280. HEREDOC;
  281. $var = b<<<HEREDOC
  282. $foo \e\f\n\r\t\v \\ \$ ${bar}
  283. HEREDOC;
  284. EOD,
  285. ];
  286. yield [
  287. <<<'EOD'
  288. <?php
  289. $var = b"\0 \00 \000 \0000 \00000";
  290. $var = b"$foo \0 \00 \000 \0000 \00000 ${bar}";
  291. $var = b<<<HEREDOC
  292. \0 \00 \000 \0000 \00000
  293. HEREDOC;
  294. $var = b<<<HEREDOC
  295. $foo \0 \00 \000 \0000 \00000 ${bar}
  296. HEREDOC;
  297. EOD,
  298. ];
  299. yield [
  300. <<<'EOD'
  301. <?php
  302. $var = b"\xA \x99 \u{0}";
  303. $var = b"$foo \xA \x99 \u{0} ${bar}";
  304. $var = b<<<HEREDOC
  305. \xA \x99 \u{0}
  306. HEREDOC;
  307. $var = b<<<HEREDOC
  308. $foo \xA \x99 \u{0} ${bar}
  309. HEREDOC;
  310. EOD,
  311. ];
  312. yield [
  313. <<<'EOD'
  314. <?php
  315. $var = b'backslash \ not escaped';
  316. $var = b'code coverage';
  317. $var = b"backslash \\ already escaped";
  318. $var = b"code coverage";
  319. $var = b<<<HEREDOC
  320. backslash \\ already escaped
  321. HEREDOC;
  322. $var = b<<<HEREDOC
  323. code coverage
  324. HEREDOC;
  325. $var = b<<<'NOWDOC'
  326. backslash \\ already escaped
  327. NOWDOC;
  328. $var = b<<<'NOWDOC'
  329. code coverage
  330. NOWDOC;
  331. EOD,
  332. ];
  333. yield [
  334. <<<'EOD'
  335. <?php
  336. $var = b"\A\a \' \8\9 \xZ \u";
  337. $var = b"$foo \A\a \' \8\9 \xZ \u ${bar}";
  338. EOD,
  339. null,
  340. ['double_quoted' => 'unescape'],
  341. ];
  342. yield [
  343. <<<'EOD'
  344. <?php
  345. $var = b<<<HEREDOC
  346. \A\Z
  347. \a\z
  348. \'
  349. \8\9
  350. \xZ
  351. \u
  352. HEREDOC;
  353. $var = b<<<HEREDOC
  354. $foo
  355. \A\Z
  356. \a\z
  357. \'
  358. \8\9
  359. \xZ
  360. \u
  361. ${bar}
  362. HEREDOC;
  363. EOD,
  364. null,
  365. ['heredoc' => 'unescape'],
  366. ];
  367. yield [
  368. <<<'EOD'
  369. <?php $var = B'String (\\\'\r\n\x0) for My\Prefix\\';
  370. EOD,
  371. ];
  372. yield [
  373. <<<'EOD'
  374. <?php $var = B'String (\\\'\\r\\n\\x0) for My\\Prefix\\';
  375. EOD,
  376. <<<'EOD'
  377. <?php $var = B'String (\\\'\r\n\x0) for My\Prefix\\';
  378. EOD,
  379. ['single_quoted' => 'escape'],
  380. ];
  381. yield [
  382. <<<'EOD'
  383. <?php
  384. $var = B"\\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z";
  385. $var = B"\\a\\b\\c\\d\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\\s\\w\\y\\z \\' \\8\\9 \\xZ \\u";
  386. $var = B"$foo \\A \\a \\' \\8\\9 \\xZ \\u ${bar}";
  387. $var = B<<<HEREDOC
  388. \\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z
  389. \\a\\b\\c\\d\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\\s\\w\\y\\z
  390. \\"
  391. \\'
  392. \\8\\9
  393. \\xZ
  394. \\u
  395. HEREDOC;
  396. $var = B<<<HEREDOC
  397. $foo \\A \\a \\" \\' \\8\\9 \\xZ \\u ${bar}
  398. HEREDOC;
  399. $var = B<<<'NOWDOC'
  400. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  401. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  402. \'
  403. \8\9
  404. \xZ
  405. \u
  406. NOWDOC;
  407. EOD,
  408. <<<'EOD'
  409. <?php
  410. $var = B"\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z";
  411. $var = B"\a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z \' \8\9 \xZ \u";
  412. $var = B"$foo \A \a \' \8\9 \xZ \u ${bar}";
  413. $var = B<<<HEREDOC
  414. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  415. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  416. \"
  417. \'
  418. \8\9
  419. \xZ
  420. \u
  421. HEREDOC;
  422. $var = B<<<HEREDOC
  423. $foo \A \a \" \' \8\9 \xZ \u ${bar}
  424. HEREDOC;
  425. $var = B<<<'NOWDOC'
  426. \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  427. \a\b\c\d\g\h\i\j\k\l\m\o\p\q\s\w\y\z
  428. \'
  429. \8\9
  430. \xZ
  431. \u
  432. NOWDOC;
  433. EOD,
  434. ];
  435. yield [
  436. <<<'EOD'
  437. <?php
  438. $var = B"\e\f\n\r\t\v \\ \$ \"";
  439. $var = B"$foo \e\f\n\r\t\v \\ \$ \" ${bar}";
  440. $var = B<<<HEREDOC
  441. \e\f\n\r\t\v \\ \$
  442. HEREDOC;
  443. $var = B<<<HEREDOC
  444. $foo \e\f\n\r\t\v \\ \$ ${bar}
  445. HEREDOC;
  446. EOD,
  447. ];
  448. yield [
  449. <<<'EOD'
  450. <?php
  451. $var = B"\0 \00 \000 \0000 \00000";
  452. $var = B"$foo \0 \00 \000 \0000 \00000 ${bar}";
  453. $var = B<<<HEREDOC
  454. \0 \00 \000 \0000 \00000
  455. HEREDOC;
  456. $var = B<<<HEREDOC
  457. $foo \0 \00 \000 \0000 \00000 ${bar}
  458. HEREDOC;
  459. EOD,
  460. ];
  461. yield [
  462. <<<'EOD'
  463. <?php
  464. $var = B"\xA \x99 \u{0}";
  465. $var = B"$foo \xA \x99 \u{0} ${bar}";
  466. $var = B<<<HEREDOC
  467. \xA \x99 \u{0}
  468. HEREDOC;
  469. $var = B<<<HEREDOC
  470. $foo \xA \x99 \u{0} ${bar}
  471. HEREDOC;
  472. EOD,
  473. ];
  474. yield [
  475. <<<'EOD'
  476. <?php
  477. $var = B'backslash \ not escaped';
  478. $var = B'code coverage';
  479. $var = B"backslash \\ already escaped";
  480. $var = B"code coverage";
  481. $var = B<<<HEREDOC
  482. backslash \\ already escaped
  483. HEREDOC;
  484. $var = B<<<HEREDOC
  485. code coverage
  486. HEREDOC;
  487. $var = B<<<'NOWDOC'
  488. backslash \\ already escaped
  489. NOWDOC;
  490. $var = B<<<'NOWDOC'
  491. code coverage
  492. NOWDOC;
  493. EOD,
  494. ];
  495. yield [
  496. <<<'EOD'
  497. <?php
  498. $var = B"\A\a \' \8\9 \xZ \u";
  499. $var = B"$foo \A\a \' \8\9 \xZ \u ${bar}";
  500. EOD,
  501. null,
  502. ['double_quoted' => 'unescape'],
  503. ];
  504. yield [
  505. <<<'EOD'
  506. <?php
  507. $var = B<<<HEREDOC
  508. \A\Z
  509. \a\z
  510. \'
  511. \8\9
  512. \xZ
  513. \u
  514. HEREDOC;
  515. $var = B<<<HEREDOC
  516. $foo
  517. \A\Z
  518. \a\z
  519. \'
  520. \8\9
  521. \xZ
  522. \u
  523. ${bar}
  524. HEREDOC;
  525. EOD,
  526. null,
  527. ['heredoc' => 'unescape'],
  528. ];
  529. yield [
  530. <<<'EOD'
  531. <?php
  532. $var = "\\bar";
  533. $var = "\\bar";
  534. $var = "\\\\bar";
  535. $var = "\\\\bar";
  536. $var = "\\\\\\bar";
  537. $var = "\\\\\\bar";
  538. EOD,
  539. <<<'EOD'
  540. <?php
  541. $var = "\bar";
  542. $var = "\\bar";
  543. $var = "\\\bar";
  544. $var = "\\\\bar";
  545. $var = "\\\\\bar";
  546. $var = "\\\\\\bar";
  547. EOD,
  548. ];
  549. yield [
  550. <<<'EOD'
  551. <?php
  552. $var = '\\bar';
  553. $var = '\\bar';
  554. $var = '\\\\bar';
  555. $var = '\\\\bar';
  556. $var = '\\\\\\bar';
  557. $var = '\\\\\\bar';
  558. EOD,
  559. <<<'EOD'
  560. <?php
  561. $var = '\bar';
  562. $var = '\\bar';
  563. $var = '\\\bar';
  564. $var = '\\\\bar';
  565. $var = '\\\\\bar';
  566. $var = '\\\\\\bar';
  567. EOD,
  568. ['single_quoted' => 'escape'],
  569. ];
  570. yield [
  571. <<<'EOD'
  572. <?php
  573. $var = <<<TXT
  574. \\bar
  575. \\bar
  576. \\\\bar
  577. \\\\bar
  578. \\\\\\bar
  579. \\\\\\bar
  580. TXT;
  581. EOD,
  582. <<<'EOD'
  583. <?php
  584. $var = <<<TXT
  585. \bar
  586. \\bar
  587. \\\bar
  588. \\\\bar
  589. \\\\\bar
  590. \\\\\\bar
  591. TXT;
  592. EOD,
  593. ];
  594. yield [
  595. <<<'EOD'
  596. <?php
  597. $var = <<<'TXT'
  598. \bar
  599. \\bar
  600. \\\bar
  601. \\\\bar
  602. \\\\\bar
  603. \\\\\\bar
  604. TXT;
  605. EOD,
  606. ];
  607. yield 'unescaped backslashes in single quoted string - backslash' => [
  608. <<<'EOD'
  609. <?php
  610. '\\';
  611. '\\\\';
  612. '\\\\\\';
  613. EOD,
  614. ];
  615. yield 'unescaped backslashes in single quoted string - reserved double quote' => [
  616. <<<'EOD'
  617. <?php
  618. '\"';
  619. '\"';
  620. '\\\"';
  621. '\\\"';
  622. '\\\\\"';
  623. '\\\\\"';
  624. '\\\\\\\"';
  625. '\\\\\\\"';
  626. EOD,
  627. <<<'EOD'
  628. <?php
  629. '\"';
  630. '\\"';
  631. '\\\"';
  632. '\\\\"';
  633. '\\\\\"';
  634. '\\\\\\"';
  635. '\\\\\\\"';
  636. '\\\\\\\\"';
  637. EOD,
  638. ];
  639. yield 'unescaped backslashes in single quoted string - reserved chars' => [
  640. <<<'EOD'
  641. <?php
  642. '\b';
  643. '\b';
  644. '\\\b';
  645. '\\\b';
  646. '\\\\\b';
  647. '\\\\\b';
  648. '\\\\\\\b';
  649. '\\\\\\\b';
  650. '\$v';
  651. '\$v';
  652. '\{$v}';
  653. '\{$v}';
  654. '\n';
  655. '\n';
  656. EOD,
  657. <<<'EOD'
  658. <?php
  659. '\b';
  660. '\\b';
  661. '\\\b';
  662. '\\\\b';
  663. '\\\\\b';
  664. '\\\\\\b';
  665. '\\\\\\\b';
  666. '\\\\\\\\b';
  667. '\$v';
  668. '\\$v';
  669. '\{$v}';
  670. '\\{$v}';
  671. '\n';
  672. '\\n';
  673. EOD,
  674. ];
  675. yield 'unescaped backslashes in double quoted string - backslash' => [
  676. <<<'EOD'
  677. <?php
  678. "\\";
  679. "\\\\";
  680. "\\\\\\";
  681. EOD,
  682. null,
  683. ['double_quoted' => 'unescape'],
  684. ];
  685. yield 'unescaped backslashes in double quoted string - reserved chars' => [
  686. <<<'EOD'
  687. <?php
  688. "\b";
  689. "\b";
  690. "\\\b";
  691. "\\\b";
  692. "\\\\\b";
  693. "\\\\\b";
  694. "\\\\\\\b";
  695. "\\\\\\\b";
  696. "\$v";
  697. "\\$v";
  698. "\{$v}";
  699. "\\{$v}";
  700. "\n";
  701. "\\n";
  702. EOD,
  703. <<<'EOD'
  704. <?php
  705. "\b";
  706. "\\b";
  707. "\\\b";
  708. "\\\\b";
  709. "\\\\\b";
  710. "\\\\\\b";
  711. "\\\\\\\b";
  712. "\\\\\\\\b";
  713. "\$v";
  714. "\\$v";
  715. "\{$v}";
  716. "\\{$v}";
  717. "\n";
  718. "\\n";
  719. EOD,
  720. ['double_quoted' => 'unescape'],
  721. ];
  722. yield 'unescaped backslashes in heredoc - backslash' => [
  723. <<<'EOD_'
  724. <?php
  725. <<<EOD
  726. \
  727. \
  728. \\\
  729. \\\
  730. \\\\\
  731. \\\\\
  732. \\\\\\\
  733. EOD;
  734. EOD_,
  735. <<<'EOD_'
  736. <?php
  737. <<<EOD
  738. \
  739. \\
  740. \\\
  741. \\\\
  742. \\\\\
  743. \\\\\\
  744. \\\\\\\
  745. EOD;
  746. EOD_,
  747. ['heredoc' => 'unescape'],
  748. ];
  749. yield 'unescaped backslashes in heredoc - reserved single quote' => [
  750. <<<'EOD_'
  751. <?php
  752. <<<EOD
  753. \'
  754. \'
  755. \\\'
  756. \\\'
  757. \\\\\'
  758. \\\\\'
  759. \\\\\\\'
  760. EOD;
  761. EOD_,
  762. <<<'EOD_'
  763. <?php
  764. <<<EOD
  765. \'
  766. \\'
  767. \\\'
  768. \\\\'
  769. \\\\\'
  770. \\\\\\'
  771. \\\\\\\'
  772. EOD;
  773. EOD_,
  774. ['heredoc' => 'unescape'],
  775. ];
  776. yield 'unescaped backslashes in heredoc - reserved double quote' => [
  777. <<<'EOD_'
  778. <?php
  779. <<<EOD
  780. \"
  781. \"
  782. \\\"
  783. \\\"
  784. \\\\\"
  785. \\\\\"
  786. \\\\\\\"
  787. EOD;
  788. EOD_,
  789. <<<'EOD_'
  790. <?php
  791. <<<EOD
  792. \"
  793. \\"
  794. \\\"
  795. \\\\"
  796. \\\\\"
  797. \\\\\\"
  798. \\\\\\\"
  799. EOD;
  800. EOD_,
  801. ['heredoc' => 'unescape'],
  802. ];
  803. yield 'unescaped backslashes in heredoc - reserved chars' => [
  804. <<<'EOD_'
  805. <?php
  806. <<<EOD
  807. \$v
  808. \\$v
  809. \{$v}
  810. \\{$v}
  811. \n
  812. \\n
  813. \b
  814. \b
  815. \\\b
  816. \\\b
  817. \\\\\b
  818. \\\\\b
  819. \\\\\\\b
  820. EOD;
  821. EOD_,
  822. <<<'EOD_'
  823. <?php
  824. <<<EOD
  825. \$v
  826. \\$v
  827. \{$v}
  828. \\{$v}
  829. \n
  830. \\n
  831. \b
  832. \\b
  833. \\\b
  834. \\\\b
  835. \\\\\b
  836. \\\\\\b
  837. \\\\\\\b
  838. EOD;
  839. EOD_,
  840. ['heredoc' => 'unescape'],
  841. ];
  842. yield 'ignored mixed implicit backslashes in single quoted string' => [
  843. <<<'EOD'
  844. <?php
  845. $var = 'a\b\\c';
  846. EOD,
  847. null,
  848. ['single_quoted' => 'ignore'],
  849. ];
  850. yield 'ignored mixed implicit backslashes in double quoted string' => [
  851. <<<'EOD'
  852. <?php
  853. $var = "a\b\\c";
  854. EOD,
  855. null,
  856. ['double_quoted' => 'ignore'],
  857. ];
  858. yield 'ignored mixed implicit backslashes in heredoc' => [
  859. <<<'EOD'
  860. <?php
  861. $var = <<<HEREDOC
  862. a\b\\c
  863. HEREDOC;
  864. EOD,
  865. null,
  866. ['heredoc' => 'ignore'],
  867. ];
  868. }
  869. }