Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Parse the whitespace surrounding equals in attribute correctly #503

Merged
merged 1 commit into from
Sep 8, 2015

Conversation

ajaybhargavb
Copy link
Contributor

Issue - #123

@NTaylorMullen @dougbu

Will add/update tests once the fix is accepted.

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/attributewhitespace.123 branch 2 times, most recently from fc23774 to 8c9a5b8 Compare August 29, 2015 00:49
// capture whitespace after attribute name (if any)
whitespaceAfterAttributeName = ReadWhile(
sym => sym.Type == HtmlSymbolType.WhiteSpace ||
sym.Type == HtmlSymbolType.NewLine);

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a change here?

@NTaylorMullen
Copy link

⌚ just for verification that the symbol types can handle the spec defined whtiespace.

@NTaylorMullen
Copy link

Design PR looks good then.

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/attributewhitespace.123 branch from 05a4705 to bdf36c6 Compare September 2, 2015 00:14
@ajaybhargavb
Copy link
Contributor Author

Updated.

@ajaybhargavb ajaybhargavb changed the title [Design] Parse the whitespace surrounding equals in attribute correctly Parse the whitespace surrounding equals in attribute correctly Sep 2, 2015
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())

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 /> ?

Copy link
Contributor Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@NTaylorMullen
Copy link

Need a few more tests:

  • Add a dynamic value one (attrName = @attrValue)
  • Add a data- variation with and without a dynamic value.
  • TagHelper test for bound/unbound variation of attribute. (Did the TagHelper bits just work?)

@NTaylorMullen
Copy link

@ajaybhargavb
Copy link
Contributor Author

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())

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<p data-foo= blah />

Copy link
Contributor

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?

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)

Copy link
Contributor

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...

@NTaylorMullen
Copy link

Need to add tests to validate following chars:

  • U+0009 CHARACTER TABULATION (tab)
  • U+000C FORM FEED (FF)

@ajaybhargavb
Copy link
Contributor Author

Updated.

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/attributewhitespace.123 branch from ab4b550 to 79f4b66 Compare September 3, 2015 01:06

// 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;
Copy link
Contributor

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.

@dougbu
Copy link
Contributor

dougbu commented Sep 3, 2015

Need to update tests with source locations to account for single-character Environment.NewLine before Travis will succeed.

@dougbu
Copy link
Contributor

dougbu commented Sep 3, 2015

@NTaylorMullen
Copy link

:shipit: once travis tests pass by addressing @dougbu's comment.

@@ -29,6 +29,39 @@ public void SimpleLiteralAttribute()
}

[Fact]
public void SimpleLiteralAttributeWithWhitespaceSurroundingEquals()
{
ParseBlockTest($"<a href \f{Environment.NewLine}= \t{Environment.NewLine}'Foo' />",
Copy link
Contributor

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.

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

@ajaybhargavb
Copy link
Contributor Author

Updated.

@dougbu
Copy link
Contributor

dougbu commented Sep 3, 2015

⌚ for remaining unaddressed feedback.

@ajaybhargavb
Copy link
Contributor Author

Updated.

@dougbu
Copy link
Contributor

dougbu commented Sep 8, 2015

:shipit:

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/attributewhitespace.123 branch 2 times, most recently from a66a17c to b02e63c Compare September 8, 2015 18:17
 - #123
 - Handled the corresponding cases in tag helper scenarios
 - Added unit and code generation tests
@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/attributewhitespace.123 branch from b02e63c to 08c8f9f Compare September 8, 2015 18:43
@ajaybhargavb ajaybhargavb merged commit 08c8f9f into dev Sep 8, 2015
@ajaybhargavb ajaybhargavb deleted the ajbaaska/attributewhitespace.123 branch September 8, 2015 18:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants