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

Razor does not correctly parse HTML attributes that have spaces surrounding the equals #123

Closed
NTaylorMullen opened this issue Sep 8, 2014 · 7 comments
Assignees
Milestone

Comments

@NTaylorMullen
Copy link

After playing around with the parse tree a bit I noticed that if you were to create HTML elements such as:

<div class   =     "foo"></div>
<div class   ="foo"></div>
<div class=    "foo"></div>

The Razor parser does not generate an accurate syntax tree (which is used to generate correct "dynamic" attribute code) that can pull the full attribute value out of the HTML output if the inner condition results to false.

Once this has been added we should also support this attribute syntax in Tag Helpers.

@dougbu
Copy link
Contributor

dougbu commented Sep 9, 2014

In generated code, this bug means WriteAttribute() doesn't get used when it should. I'm not sure about the downstream impact...

Quick samples:

  • <div class=@classy/> separates the attribute and the value expression into their own markup Blocks in the syntax tree and generates
            WriteAttribute("class", Tuple.Create(" class=", 82), Tuple.Create("", 96), 
            Tuple.Create(Tuple.Create("", 89), Tuple.Create<System.Object, System.Int32>(
#line 6 ""
                classy

#line default
#line hidden
  • <div class= @classy/> includes " class= " in the TagBlock for <div and generates
            WriteLiteral("<html>\r\n  <head>\r\n   <title>This is a title</title>\r\n  </head>\r\n  <body>\r\n    <di" +
"v class =");
            Write(
#line 6 ""
                 classy

#line default
#line hidden
            );

@yishaigalatzer yishaigalatzer removed this from the 4.0.0-beta1 milestone Sep 10, 2014
@yishaigalatzer yishaigalatzer added this to the 4.0.0-rc1 milestone Sep 17, 2014
@NTaylorMullen NTaylorMullen changed the title Razor does not correctly parse HTML attributes that have spaces surround the equals Razor does not correctly parse HTML attributes that have spaces surrounding the equals Oct 1, 2014
@yishaigalatzer yishaigalatzer modified the milestones: 4.0.0, 4.0.0-beta3 Jan 15, 2015
@yishaigalatzer
Copy link
Contributor

Consider porting back to fix https://aspnetwebstack.codeplex.com/workitem/2149 when this gets fixed

@ChrisKlug
Copy link

According to the W3.org spec, you are not supposed to be allowed to have a space between the attribute name and = though. Should it still allow that? If it is just a matter of getting the HtmlMarkupParser to accept spaces before and after the = character, I might be able to help out with that if you want me to?

@NTaylorMullen
Copy link
Author

@ChrisKlug the HTML5 spec allows it. See: http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-double-quoted

A double-quoted attribute value is specified by providing the following parts in exactly the following order:

  1. an attribute name
  2. zero or more space characters
  3. a single "=" character
  4. zero or more space characters
  5. a single """ character
  6. an attribute value
  7. a """ character

@ChrisKlug
Copy link

You are absolutely correct. I read the http://www.w3.org/html/wg/drafts/html/master/syntax.html#attribute-name-state state-handling wrong. I guess I should stop questioning things now... :)

@NTaylorMullen
Copy link
Author

Note place for reaction: 4c5f9c5#diff-58782e50bed88f4f2f70af4835346999R476

@danroth27 danroth27 modified the milestones: 4.0.0-beta6, 4.0.0-beta5 May 11, 2015
@Eilon Eilon modified the milestones: 4.0.0-beta6, 4.0.0-beta7 Jun 29, 2015
@Eilon Eilon assigned ajaybhargavb and unassigned sornaks Jul 29, 2015
@Eilon Eilon modified the milestones: 4.0.0-beta7, 4.0.0-beta8 Aug 7, 2015
ajaybhargavb added a commit that referenced this issue Sep 8, 2015
 - #123
 - Handled the corresponding cases in tag helper scenarios
 - Added unit and code generation tests
ajaybhargavb added a commit that referenced this issue Sep 8, 2015
 - #123
 - Handled the corresponding cases in tag helper scenarios
 - Added unit and code generation tests
ajaybhargavb added a commit that referenced this issue Sep 8, 2015
 - #123
 - Handled the corresponding cases in tag helper scenarios
 - Added unit and code generation tests
@ajaybhargavb
Copy link
Contributor

08c8f9f

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants