Skip to content

Commit cd226a3

Browse files
authored
fix(view): handle boolean attribute followed by non space whitespace or self-closing tags (#1632)
1 parent ba0c6ea commit cd226a3

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/view/src/Parser/TempestViewLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private function lexTag(): array
117117

118118
$attributeName = $this->consumeWhile(self::WHITESPACE);
119119

120-
$attributeName .= $this->consumeUntil('= >');
120+
$attributeName .= $this->consumeUntil(self::WHITESPACE . '=/>');
121121

122122
$hasValue = $this->seek() === '=';
123123

packages/view/tests/TempestViewLexerTest.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,40 @@ public function test_self_closing_tag_with_attributes(): void
9696
);
9797
}
9898

99+
public function test_boolean_attribute_with_self_closing_tag(): void
100+
{
101+
$code = '<input disabled/>';
102+
103+
$tokens = new TempestViewLexer($code)->lex();
104+
105+
$this->assertTokens(
106+
expected: [
107+
new Token('<input', TokenType::OPEN_TAG_START),
108+
new Token(' disabled', TokenType::ATTRIBUTE_NAME),
109+
new Token('/>', TokenType::SELF_CLOSING_TAG_END),
110+
],
111+
actual: $tokens,
112+
);
113+
}
114+
115+
public function test_boolean_attribute_with_newline(): void
116+
{
117+
$code = '<div hidden
118+
></div>';
119+
120+
$tokens = new TempestViewLexer($code)->lex();
121+
122+
$this->assertTokens(
123+
expected: [
124+
new Token('<div', TokenType::OPEN_TAG_START),
125+
new Token(' hidden', TokenType::ATTRIBUTE_NAME),
126+
new Token("\n>", TokenType::OPEN_TAG_END),
127+
new Token('</div>', TokenType::CLOSING_TAG),
128+
],
129+
actual: $tokens,
130+
);
131+
}
132+
99133
#[TestWith(['</x-foo>'])]
100134
public function test_closing_tag(string $tag): void
101135
{
@@ -132,9 +166,9 @@ class=', TokenType::ATTRIBUTE_NAME),
132166
foo=', TokenType::ATTRIBUTE_NAME),
133167
new Token('"bar"', TokenType::ATTRIBUTE_VALUE),
134168
new Token('
135-
x-foo
136-
', TokenType::ATTRIBUTE_NAME),
137-
new Token(' :baz=', TokenType::ATTRIBUTE_NAME),
169+
x-foo', TokenType::ATTRIBUTE_NAME),
170+
new Token('
171+
:baz=', TokenType::ATTRIBUTE_NAME),
138172
new Token('"true"', TokenType::ATTRIBUTE_VALUE),
139173
new Token("\n>", TokenType::OPEN_TAG_END),
140174
new Token('

0 commit comments

Comments
 (0)