|
5 | 5 | namespace Sabberworm\CSS\Tests\Unit\Value; |
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase; |
| 8 | +use Sabberworm\CSS\OutputFormat; |
8 | 9 | use Sabberworm\CSS\Value\CSSString; |
9 | 10 | use Sabberworm\CSS\Value\PrimitiveValue; |
10 | 11 | use Sabberworm\CSS\Value\Value; |
@@ -107,4 +108,42 @@ public function getArrayRepresentationIncludesContents(): void |
107 | 108 | self::assertArrayHasKey('contents', $result); |
108 | 109 | self::assertSame($contents, $result['contents']); |
109 | 110 | } |
| 111 | + |
| 112 | + /** |
| 113 | + * @test |
| 114 | + */ |
| 115 | + public function doesNotEscapeSingleQuotesThatDoNotNeedToBeEscaped(): void |
| 116 | + { |
| 117 | + $input = "data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none'" . |
| 118 | + " xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd'" . |
| 119 | + " d='M14.3145 2 3V11.9987H17.5687L18 8.20761H14.3145L14.32 6.31012C14.32 5.32134 14.4207" . |
| 120 | + ' 4.79153 15.9426 4.79153H17.977V1H14.7223C10.8129 1 9.43687 2.83909 9.43687 ' . |
| 121 | + " 5.93187V8.20804H7V11.9991H9.43687V23H14.3145Z' fill='black'/%3E%3C/svg%3E%0A"; |
| 122 | + |
| 123 | + $outputFormat = OutputFormat::createPretty(); |
| 124 | + |
| 125 | + self::assertSame("\"{$input}\"", (new CSSString($input))->render($outputFormat)); |
| 126 | + |
| 127 | + $outputFormat->setStringQuotingType("'"); |
| 128 | + |
| 129 | + $expected = str_replace("'", "\\'", $input); |
| 130 | + |
| 131 | + self::assertSame("'{$expected}'", (new CSSString($input))->render($outputFormat)); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @test |
| 136 | + */ |
| 137 | + public function doesNotEscapeDoubleQuotesThatDoNotNeedToBeEscaped(): void |
| 138 | + { |
| 139 | + $input = '"Hello World"'; |
| 140 | + |
| 141 | + $outputFormat = OutputFormat::createPretty(); |
| 142 | + |
| 143 | + self::assertSame('"\\"Hello World\\""', (new CSSString($input))->render($outputFormat)); |
| 144 | + |
| 145 | + $outputFormat->setStringQuotingType("'"); |
| 146 | + |
| 147 | + self::assertSame("'{$input}'", (new CSSString($input))->render($outputFormat)); |
| 148 | + } |
110 | 149 | } |
0 commit comments