-
Notifications
You must be signed in to change notification settings - Fork 222
Parse the whitespace surrounding equals in attribute correctly #503
Conversation
fc23774
to
8c9a5b8
Compare
// capture whitespace after attribute name (if any) | ||
whitespaceAfterAttributeName = ReadWhile( | ||
sym => sym.Type == HtmlSymbolType.WhiteSpace || | ||
sym.Type == HtmlSymbolType.NewLine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this is just fine but we should validate that this newline and the previous whitespace symbol types can handle all the valid whitespace/newline characters defined by the spec for attributes:
- U+0020 SPACE
- U+0009 CHARACTER TABULATION (tab)
- U+000A LINE FEED (LF)
- U+000C FORM FEED (FF)
- U+000D CARRIAGE RETURN (CR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked and yes, it handles all characters in list. I'll add them to some tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please unwrap this. Hard to read with expression split up but lambda parameter mixed in with one part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a change here?
⌚ just for verification that the symbol types can handle the spec defined whtiespace. |
Design PR looks good then. |
05a4705
to
bdf36c6
Compare
Updated. |
while (!EndOfFile && !IsEndOfAttributeValue(quote, CurrentSymbol)) | ||
// Read the attribute value only if the value is quoted | ||
// or if there is no whitespace between '=' and the unquoted value. | ||
if (quote != HtmlSymbolType.Unknown || !whitespaceAfterEquals.Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens now with <input name=@value />
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition will return true
. No change in the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Need a few more tests:
|
⌚ |
Updated. |
@@ -557,6 +587,11 @@ private void AttributePrefix(IEnumerable<HtmlSymbol> whitespace, IEnumerable<Htm | |||
// Output the attribute name, the equals and optional quote. Ex: foo=" | |||
Output(SpanKind.Markup); | |||
|
|||
if (quote == HtmlSymbolType.Unknown && whitespaceAfterEquals.Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What text input makes this evaluate to true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p data-foo= blah />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this evaluate to false
? You're in an else
block for quote != HtmlSymbolType.Unknown || !whitespaceAfterEquals.Any()
. Do a bit of Boolean algebra on !(A != B || !C)
and you get A == B && C
.
Looks line line 594 is unreachable. What is lost if that code is never evaluated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. @dougbu you may be misreading the diff. This is the else
of if (attributeCanBeConditional)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NTaylorMullen yup, thought I expanded everything in between but noooo...
⌚ Need to add tests to validate following chars:
|
Updated. |
ab4b550
to
79f4b66
Compare
|
||
// TODO: Handle malformed tags, if there's an '=' then there MUST be a value. | ||
// https://github.com/aspnet/Razor/issues/104 | ||
|
||
SourceLocation symbolStartLocation; | ||
|
||
// Skip the whitespace preceding the start of the attribute value. | ||
var valueStartIndex = i + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a code comment explaining + 1
skips over the =
sign.
Need to update tests with source locations to account for single-character |
⌚ |
@@ -29,6 +29,39 @@ public void SimpleLiteralAttribute() | |||
} | |||
|
|||
[Fact] | |||
public void SimpleLiteralAttributeWithWhitespaceSurroundingEquals() | |||
{ | |||
ParseBlockTest($"<a href \f{Environment.NewLine}= \t{Environment.NewLine}'Foo' />", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of Environment.NewLine
instead of \r\n
means you're not testing '\r'
on Linux. I.e. I suggest being explicit about the characters and dropping Environment.NewLine
. That should also fix the problems testing on Linux because the source locations will be identical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @dougbu because:
\r\n is Windows., \n is Unix and \r is Mac
Updated. |
⌚ for remaining unaddressed feedback. |
Updated. |
|
a66a17c
to
b02e63c
Compare
- #123 - Handled the corresponding cases in tag helper scenarios - Added unit and code generation tests
b02e63c
to
08c8f9f
Compare
Issue - #123
@NTaylorMullen @dougbu
Will add/update tests once the fix is accepted.