-
Notifications
You must be signed in to change notification settings - Fork 223
Razor does not respect html comments inside a razor block #302
Comments
@yishaigalatzer HTML 5 (like XML) disallows ending a comment with just out of interest, does @{
<text><!-- Hello, I'm a comment that will break razor --></text>
} or the same with the not-well-formed triple-dash comment result in a generated HTML comment? |
Browsers do allow it, so we can be nicer about it |
This issue is scoped to odd number of hyphens before diff --git a/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs b/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs
index dfb1c5e..4a35c33 100644
--- a/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs
+++ b/src/Microsoft.AspNet.Razor/Parser/HtmlLanguageCharacteristics.cs
@@ -43,6 +43,8 @@ public override string GetSample(HtmlSymbolType type)
return "?";
case HtmlSymbolType.DoubleHyphen:
return "--";
+ case HtmlSymbolType.SingleHyphen:
+ return "-";
case HtmlSymbolType.LeftBracket:
return "[";
case HtmlSymbolType.CloseAngle:
diff --git a/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs b/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs
index 0f6a6d5..4ecd074 100644
--- a/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs
+++ b/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs
@@ -252,7 +252,11 @@ private bool BangTag()
if (CurrentSymbol.Type == HtmlSymbolType.DoubleHyphen)
{
AcceptAndMoveNext();
- return AcceptUntilAll(HtmlSymbolType.DoubleHyphen, HtmlSymbolType.CloseAngle);
+ while(CurrentSymbol.Type == HtmlSymbolType.SingleHyphen)
+ {
+ AcceptAndMoveNext();
+ }
+ return AcceptUntilAll(HtmlSymbolType.CloseAngle);
}
else if (CurrentSymbol.Type == HtmlSymbolType.LeftBracket)
{
diff --git a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbolType.cs b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbolType.cs
index 27cbd7e..ab27157 100644
--- a/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbolType.cs
+++ b/src/Microsoft.AspNet.Razor/Tokenizer/Symbols/HtmlSymbolType.cs
@@ -17,6 +17,7 @@ public enum HtmlSymbolType
ForwardSlash, // /
QuestionMark, // ?
DoubleHyphen, // --
+ SingleHyphen, // -
LeftBracket, // [
CloseAngle, // >
RightBracket, // ] |
@NTaylorMullen can you verify if this is fixed? If so, please add a test for it. |
Yup, this is fixed 😄 |
And there's a test for this exact case? |
Yup 😄 |
Actually I don't see that case there. This particular case has 2 dashes |
(All the cases in that test have a matching number of dashes.) |
Sure |
Let's just add this test and close this out. |
See original comment - https://aspnetwebstack.codeplex.com/workitem/2233
Does not work
Works
If you have more than 2 dashes at the end of the comment - Razor shows compilation error. Only 2 dashes are accepted. However, if this comment is outside a code block, it works fine.
The text was updated successfully, but these errors were encountered: