Skip to content

Commit ffed1e0

Browse files
committed
keep track of original attr name
1 parent b4d3c68 commit ffed1e0

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/Template/Parser/StreamingCompiler.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ private function resetState(): void
133133
$this->selfClosing = false;
134134
$this->attributeValue = '';
135135
$this->attributeName = '';
136+
$this->originalAttributeName = '';
136137
$this->nameBuffer = '';
137138
$this->isClosing = false;
138139
}
@@ -545,7 +546,8 @@ private function renderTagName(Document $document): Document
545546
private function renderBeforeAttributeName(Document $document): Document
546547
{
547548
$oops = function (string $c, Closure $next) use ($document) {
548-
$this->attributeName = $c;
549+
$this->attributeName = strtolower($c);
550+
$this->originalAttributeName = $c;
549551
$this->attributeValue = '';
550552
return $next($document);
551553
};
@@ -560,6 +562,7 @@ private function renderBeforeAttributeName(Document $document): Document
560562
return $result;
561563
}
562564
$this->attributeName = '';
565+
$this->originalAttributeName = '';
563566
$this->attributeValue = '';
564567
return $document->reconsume($this->renderAttributeName(...));
565568
}
@@ -1130,6 +1133,8 @@ private function renderBogusDocType(Document $document): Document
11301133
return $this->renderBogusDocType($document);
11311134
}
11321135

1136+
private string $originalAttributeName = '';
1137+
11331138
private function renderAttributeName(Document $document): Document
11341139
{
11351140
//$selectionStart = $document->mark();
@@ -1143,6 +1148,7 @@ private function renderAttributeName(Document $document): Document
11431148
return $result;
11441149
}
11451150
$this->attributeName .= strtolower($char);
1151+
$this->originalAttributeName .= $char;
11461152
goto renderAttributeName;
11471153
}
11481154

@@ -1153,7 +1159,7 @@ private function renderBeforeAttributeValue(Document $document): Document
11531159
'"' => $this->renderAttributeValueDoubleQuoted($document),
11541160
"'" => $this->renderAttributeValueSingleQuoted($document),
11551161
'>' => (function () use ($document) {
1156-
$this->setAttribute($this->attributeName);
1162+
$this->setAttribute($this->originalAttributeName);
11571163
return $document;
11581164
})(),
11591165
default => $this->renderAttributeValueUnquoted($document),
@@ -1207,7 +1213,7 @@ private function processAttributes(Document $document): Document
12071213
$value = $this->escaper->escapeHtmlAttr($originalValue);
12081214
// escaper doesn't escape single quotes, so we do that here.
12091215
$value = str_replace("'", ''', $value);
1210-
$this->setAttribute($this->attributeName, $originalValue);
1216+
$this->setAttribute($this->originalAttributeName, $originalValue);
12111217
if ($value !== $this->attributeValue) {
12121218
// we need to update the rendered html too...
12131219
$here = $document->mark();
@@ -1263,8 +1269,8 @@ private function renderAttributeValueUnquoted(Document $document): Document
12631269

12641270
private function renderAfterAttributeName(Document $document): Document
12651271
{
1266-
if (!empty($this->attributeName) && !array_key_exists($this->attributeName, $this->attributes)) {
1267-
$this->setAttribute($this->attributeName);
1272+
if (!empty($this->attributeName) && !array_key_exists($this->originalAttributeName, $this->attributes)) {
1273+
$this->setAttribute($this->originalAttributeName);
12681274
}
12691275
$result = match ($document->consume()) {
12701276
"\t", "\n", "\f", " " => $this->renderAfterAttributeName($document),
@@ -1278,6 +1284,7 @@ private function renderAfterAttributeName(Document $document): Document
12781284
}
12791285
$this->attributeName = '';
12801286
$this->attributeValue = '';
1287+
$this->originalAttributeName = '';
12811288
return $document->reconsume($this->renderAttributeName(...));
12821289
}
12831290

tests/StreamingTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,24 +265,24 @@ public function render()
265265
it('passes variables correctly', function () {
266266
$container = containerWithComponents([
267267
'echo' => new class {
268-
public function render(string $test = ''): string
268+
public function render(string $Test = ''): string
269269
{
270-
return $test;
270+
return $Test;
271271
}
272272
},
273273
'child' => new class {
274-
public function render(string $test = ''): string
274+
public function render(string $Test = ''): string
275275
{
276-
return "<div>{{$test}}<children/></div>";
276+
return "<div>{{$Test}}<children/></div>";
277277
}
278278
}
279279
]);
280280

281281
$streamer = $container->get(StreamingCompiler::class);
282282
$document = <<<HTML
283-
<echo test="{some text}" />
284-
<child test="{outer text}">
285-
<echo test="{inner text}" />
283+
<echo Test="{some text}" />
284+
<child Test="{outer text}">
285+
<echo Test="{inner text}" />
286286
</child>
287287
HTML;
288288
$result = $streamer->compile($document);

0 commit comments

Comments
 (0)