Skip to content

Commit db8eb8d

Browse files
committed
wip
1 parent 7102947 commit db8eb8d

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
"nette/php-generator": "^4.1.6",
2626
"nikic/php-parser": "^5.3",
2727
"php": "^8.4",
28-
"psr-discovery/http-client-implementations": "^1.4",
29-
"psr-discovery/http-factory-implementations": "^1.2",
28+
"psr-discovery/http-client-implementations": "^1.2",
29+
"psr-discovery/http-factory-implementations": "^1.4",
3030
"psr/cache": "^3.0",
3131
"psr/clock": "^1.0.0",
3232
"psr/http-client": "^1.0.0",
3333
"psr/http-factory": "^1.0",
3434
"psr/http-message": "^1.0|^2.0",
3535
"psr/log": "^3.0.0",
36-
"rector/rector": "^2.1",
36+
"rector/rector": "2.2.1",
3737
"symfony/cache": "^7.3",
3838
"symfony/mailer": "^7.2.6",
3939
"symfony/process": "^7.3",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Tempest\View\Exceptions;
4+
5+
use Exception;
6+
7+
final class AttributesWithSingleQuotesWereNotAllowed extends Exception
8+
{
9+
}

packages/view/src/Parser/TempestViewLexer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Tempest\View\Parser;
44

5+
use Tempest\View\Exceptions\AttributesWithSingleQuotesWereNotAllowed;
6+
57
final class TempestViewLexer
68
{
79
private const string WHITESPACE = PHP_EOL . "\n\t\f ";
@@ -131,6 +133,10 @@ private function lexTag(): array
131133
);
132134

133135
if ($hasValue) {
136+
if ($this->seek() === '\'') {
137+
throw new AttributesWithSingleQuotesWereNotAllowed();
138+
}
139+
134140
$attributeValue = $this->consumeIncluding('"');
135141
$attributeValue .= $this->consumeIncluding('"');
136142

packages/view/tests/TempestViewLexerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\Attributes\TestWith;
66
use PHPUnit\Framework\TestCase;
7+
use Tempest\View\Exceptions\AttributesWithSingleQuotesWereNotAllowed;
78
use Tempest\View\Parser\TempestViewLexer;
89
use Tempest\View\Parser\Token;
910
use Tempest\View\Parser\TokenCollection;
@@ -346,6 +347,17 @@ public function test_xml(): void
346347
);
347348
}
348349

350+
public function test_single_quote_attributes(): void
351+
{
352+
$html = <<<HTML
353+
<div class='hello'></div>
354+
HTML;
355+
356+
$this->expectException(AttributesWithSingleQuotesWereNotAllowed::class);
357+
358+
new TempestViewLexer($html)->lex();
359+
}
360+
349361
private function assertTokens(array $expected, TokenCollection $actual): void
350362
{
351363
$this->assertCount(count($expected), $actual);

tests/Integration/View/TempestViewRendererTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Tests\Tempest\Integration\View;
66

77
use Tempest\Support\Html\HtmlString;
8+
use Tempest\View\Exceptions\AttributesWithSingleQuotesWereNotAllowed;
89
use Tempest\View\Exceptions\ElementWasInvalid;
910
use Tempest\View\ViewCache;
1011
use Tests\Tempest\Fixtures\Controllers\RelativeViewController;
@@ -847,4 +848,13 @@ public function test_parse_rss_feed(): void
847848
</feed>
848849
RSS, $parsed);
849850
}
851+
852+
public function test_attributes_with_single_quotes(): void
853+
{
854+
$this->expectException(AttributesWithSingleQuotesWereNotAllowed::class);
855+
856+
$html = $this->render(<<<'HTML'
857+
<div class='hello'></div>
858+
HTML);
859+
}
850860
}

0 commit comments

Comments
 (0)