-
Notifications
You must be signed in to change notification settings - Fork 222
TagHelper attributes with no value cannot be used in TagHelpers #220
Comments
supporting this would go beyond the XHTML restrictions elsewhere in the system. the only special case I'm aware of is |
@dougbu this is supported in HTML 5: http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty |
Agreed. However we restrict ourselves to generating and accepting only the XHTML subset of HTML 5. |
Hmm? Where do we restrict ourselves to generating and accepting only the XHTML subset of HTML5? |
This bug is just one example where Razor doesn't support non-XHTML Another is tag helpers not handling an empty element unless it's written as a self-closing tag. On the generation side, Side question: Why did you add the "bug" tag for this issue? Seems more like an enhancement to support additional syntax for already-supported HTML features. Even more like a part of a larger "HTML short-form" feature that would touch a lot of the Razor parser as well as the HTML and tag helper infrastructure. |
It's marked as a bug because we're making the move to support HTML5. That was also why we modified |
Low importance: The analogy doesn't hold because a .cshtml file containing attributes using various cases can still generate a valid-looking XHTML document. But perhaps you're right and we should normalize the case of all attributes we write, regardless of the user's input. |
The key issue here is this: In razor 2 or 3 when the user wrote <input required /> We rendered <input required /> But with tag helpers (input tag helper for example) <input asp-for="FieldName" required /> We will trigger a parsing error and you will have to type <input asp-for="FieldName" required="true" /> |
when this bug is fixed, will need to modify the expectations in https://github.com/aspnet/Mvc/tree/dev/test/Microsoft.AspNet.Mvc.FunctionalTests/Compiler/Resources files as well as one HTML helper test file (see https://github.com/aspnet/Mvc/blob/dev/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/OrderUsingHtmlHelpers.cshtml#L72) that mimics current tag helper results |
With issue #289 all /cc @DamianEdwards |
I think we just shouldn't support bound properties that don't have a value specified, i.e. parser error. |
@ChrisKlug Can completely understand the frustration. Razor actually as whole today doesn't parse attributes correctly even when not using |
Just to be clear, the Tag Helper will be able to see the attribute once we fix other things we're currently working on. You'll be able to see the attribute from Also, you'll be able to target a Tag Helper based on the existence of such a property using the |
Ok, great! It just caused me a heap of headscratching when I couldn't get my TagHelper to run when the "required" attribute didn't have a value. After a bit of looking, it seemed as it could be solved by changing some not too complicated things in the attribute parsing, but I don't know if that would affect something else... But fixing that seemed like a small thing that could be fixed by a quick pull request, but if it is bigger I will stay out of your way... |
@ChrisKlug The parsing logic change isn't much. Writing the tests for it will be the time sink, prob 20% feature 80% test time for this one 😄 |
- Updated the Razor parser to understand minimized attributes instead of just treating them like plain text. This just involved encompassing minimized attributes in their own blocks just like the other attributes found on the HTML tag. - Updated TagHelperParseTreeRewriter to only accept minimized attributes for unbound attributes. - Updated IReadOnlyTagHelperAttribute/TagHelperAttribute to have a Minimized property to indicate that an attribute was minimized. - Updated parser level block structures to represent minimized attributes as null syntax tree nodes. - Updated chunk level structures to represent minimized attributes as null chunks. #220
- Added parse level rewriting tests to validate new TagHelper rewritten structures for minimized attributes. - Updated existing parser tests to understand minimized attributes. - Added codegen test to validate understanding of minimized attributes. - Added TagHelperExecutionContext tests to validate maintaining of runtime TagHelperOutput tests. #220
- Updated the Razor parser to understand minimized attributes instead of just treating them like plain text. This just involved encompassing minimized attributes in their own blocks just like the other attributes found on the HTML tag. - Updated TagHelperParseTreeRewriter to only accept minimized attributes for unbound attributes. - Updated IReadOnlyTagHelperAttribute/TagHelperAttribute to have a Minimized property to indicate that an attribute was minimized. - Updated parser level block structures to represent minimized attributes as null syntax tree nodes. - Updated chunk level structures to represent minimized attributes as null chunks. #220
- Added parse level rewriting tests to validate new TagHelper rewritten structures for minimized attributes. - Updated existing parser tests to understand minimized attributes. - Added codegen test to validate understanding of minimized attributes. - Added TagHelperExecutionContext tests to validate maintaining of runtime TagHelperOutput tests. - Refactored part of the TagHelperParseTreeRewriterTest file into a base class file so we can make better rewriting tests. #220
- Updated the Razor parser to understand minimized attributes instead of just treating them like plain text. This just involved encompassing minimized attributes in their own blocks just like the other attributes found on the HTML tag. - Updated TagHelperParseTreeRewriter to only accept minimized attributes for unbound attributes. - Updated IReadOnlyTagHelperAttribute/TagHelperAttribute to have a Minimized property to indicate that an attribute was minimized. - Updated parser level block structures to represent minimized attributes as null syntax tree nodes. - Updated chunk level structures to represent minimized attributes as null chunks. #220
- Added parse level rewriting tests to validate new TagHelper rewritten structures for minimized attributes. - Updated existing parser tests to understand minimized attributes. - Added codegen test to validate understanding of minimized attributes. - Added TagHelperExecutionContext tests to validate maintaining of runtime TagHelperOutput tests. - Refactored part of the TagHelperParseTreeRewriterTest file into a base class file so we can make better rewriting tests. #220
- Updated the Razor parser to understand minimized attributes instead of just treating them like plain text. This just involved encompassing minimized attributes in their own blocks just like the other attributes found on the HTML tag. - Updated TagHelperParseTreeRewriter to only accept minimized attributes for unbound attributes. - Updated IReadOnlyTagHelperAttribute/TagHelperAttribute to have a Minimized property to indicate that an attribute was minimized. - Updated parser level block structures to represent minimized attributes as null syntax tree nodes. - Updated chunk level structures to represent minimized attributes as null chunks. #220
- Added parse level rewriting tests to validate new TagHelper rewritten structures for minimized attributes. - Updated existing parser tests to understand minimized attributes. - Added codegen test to validate understanding of minimized attributes. - Added TagHelperExecutionContext tests to validate maintaining of runtime TagHelperOutput tests. - Refactored part of the TagHelperParseTreeRewriterTest file into a base class file so we can make better rewriting tests. #220
- Added the ability for the WriteTagHelperAsync in RazorPage.cs to understand minimized attributes.
- Added unit and functional test.
- Updated the Razor parser to understand minimized attributes instead of just treating them like plain text. This just involved encompassing minimized attributes in their own blocks just like the other attributes found on the HTML tag. - Updated TagHelperParseTreeRewriter to only accept minimized attributes for unbound attributes. - Updated IReadOnlyTagHelperAttribute/TagHelperAttribute to have a Minimized property to indicate that an attribute was minimized. - Updated parser level block structures to represent minimized attributes as null syntax tree nodes. - Updated chunk level structures to represent minimized attributes as null chunks. #220
- Added parse level rewriting tests to validate new TagHelper rewritten structures for minimized attributes. - Updated existing parser tests to understand minimized attributes. - Added codegen test to validate understanding of minimized attributes. - Added TagHelperExecutionContext tests to validate maintaining of runtime TagHelperOutput tests. - Refactored part of the TagHelperParseTreeRewriterTest file into a base class file so we can make better rewriting tests. #220
- Added the ability for the WriteTagHelperAsync in RazorPage.cs to understand minimized attributes.
- Added unit and functional test.
…rt II - relates to #89 because that changes `string` property checks and needs this refactor - determine `string`-ness when creating `TagHelperAttributeDescriptor`s - add `TagHelperAttributeDescriptor.IsStringProperty` (set in constructor) - avoid repeated `string` comparisons and be more explicit - change `TagHelperBlockRewriter` to centralize more of the `string`-ness determination - also add `TryParseResult` DTO, avoiding multiple `out` parameters - refactor `CSharpTagHelperCodeRenderer` to allow reuse of core attribute value rendering - test all of it - add `TagHelperDescriptorTest` to confirm serialization / deserialization minor: - fix `TagHelperBlockRewriter.TryParseBlock()` end quote removal when tag is malformed nits: - remove dangling mention of fixed bug #220 - make recently-added `TagHelperBlockRewriterTest` tests realistic - multiple `TagHelperDescriptor`s for same tag helper have identical `Attributes`
Razor does not correctly parse HTML attributes that have no value.
After playing around with the parse tree a bit I noticed that if you were to create HTML elements such as:
The Razor parser does not generate an accurate syntax tree. This in turn results in the generated code not calling
WriteAttribute
and furthermore withTagHelper
s does not allow us to pull the attributes from an HTML element easily.Once this has been added we should also support this attribute syntax in Tag Helpers.
The text was updated successfully, but these errors were encountered: