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

Commit b8af599

Browse files
committed
Addressed feedback
1 parent bdf36c6 commit b8af599

File tree

6 files changed

+128
-17
lines changed

6 files changed

+128
-17
lines changed

src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ private void AttributePrefix(
587587
// Output the attribute name, the equals and optional quote. Ex: foo="
588588
Output(SpanKind.Markup);
589589

590-
if (whitespaceAfterEquals.Any())
590+
if (quote == HtmlSymbolType.Unknown && whitespaceAfterEquals.Any())
591591
{
592592
return;
593593
}

src/Microsoft.AspNet.Razor/Parser/TagHelpers/TagHelperBlockRewriter.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,32 @@ private static TryParseResult TryParseSpan(
206206
// The goal here is to consume the equal sign and the optional single/double-quote.
207207

208208
// The coming symbols will either be a quote or value (in the case that the value is unquoted).
209-
// Spaces after/before the equal symbol are not yet supported:
210-
// https://github.com/aspnet/Razor/issues/123
211209

212210
// TODO: Handle malformed tags, if there's an '=' then there MUST be a value.
213211
// https://github.com/aspnet/Razor/issues/104
214212

215213
SourceLocation symbolStartLocation;
216214

215+
// Skip the whitespace preceding the start of the attribute value.
216+
var valueStartIndex = i + 1;
217+
while(valueStartIndex < htmlSymbols.Length &&
218+
(htmlSymbols[valueStartIndex].Type == HtmlSymbolType.WhiteSpace ||
219+
htmlSymbols[valueStartIndex].Type == HtmlSymbolType.NewLine))
220+
{
221+
valueStartIndex++;
222+
}
223+
217224
// Check for attribute start values, aka single or double quote
218-
if ((i + 1) < htmlSymbols.Length && IsQuote(htmlSymbols[i + 1]))
225+
if (valueStartIndex < htmlSymbols.Length && IsQuote(htmlSymbols[valueStartIndex]))
219226
{
220227
// Move past the attribute start so we can accept the true value.
221-
i++;
222-
symbolStartLocation = htmlSymbols[i].Start;
228+
valueStartIndex++;
229+
symbolStartLocation = htmlSymbols[valueStartIndex].Start;
223230

224231
// If there's a start quote then there must be an end quote to be valid, skip it.
225232
symbolOffset = 1;
233+
234+
i = valueStartIndex - 1;
226235
}
227236
else
228237
{

test/Microsoft.AspNet.Razor.Test/CodeGenerators/CSharpTagHelperRenderingTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,9 @@ public static TheoryData DesignTimeTagHelperTestData
856856
characterOffsetIndex: 14,
857857
contentLength: 11),
858858
BuildLineMapping(
859-
documentAbsoluteIndex: 62,
859+
documentAbsoluteIndex: 63,
860860
documentLineIndex: 3,
861-
documentCharacterOffsetIndex: 26,
861+
documentCharacterOffsetIndex: 27,
862862
generatedAbsoluteIndex: 1289,
863863
generatedLineIndex: 39,
864864
generatedCharacterOffsetIndex: 28,
@@ -871,9 +871,9 @@ public static TheoryData DesignTimeTagHelperTestData
871871
characterOffsetIndex: 30,
872872
contentLength: 0),
873873
BuildLineMapping(
874-
documentAbsoluteIndex: 88,
874+
documentAbsoluteIndex: 89,
875875
documentLineIndex: 4,
876-
documentCharacterOffsetIndex: 12,
876+
documentCharacterOffsetIndex: 13,
877877
generatedAbsoluteIndex: 1789,
878878
generatedLineIndex: 54,
879879
generatedCharacterOffsetIndex: 19,
@@ -1488,6 +1488,7 @@ public static TheoryData RuntimeTimeTagHelperTestData
14881488
{
14891489
{ "SingleTagHelper", null, DefaultPAndInputTagHelperDescriptors },
14901490
{ "SingleTagHelperWithNewlineBeforeAttributes", null, DefaultPAndInputTagHelperDescriptors },
1491+
{ "TagHelpersWithWeirdlySpacedAttributes", null, DefaultPAndInputTagHelperDescriptors },
14911492
{ "BasicTagHelpers", null, DefaultPAndInputTagHelperDescriptors },
14921493
{ "BasicTagHelpers.RemoveTagHelper", null, DefaultPAndInputTagHelperDescriptors },
14931494
{ "BasicTagHelpers.Prefixed", null, PrefixedPAndInputTagHelperDescriptors },

test/Microsoft.AspNet.Razor.Test/Parser/Html/HtmlAttributeTest.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ public void SimpleLiteralAttributeWithWhitespaceSurroundingEquals()
4242
Factory.Markup(" />").Accepts(AcceptedCharacters.None))));
4343
}
4444

45+
[Fact]
46+
public void DynamicAttributeWithWhitespaceSurroundingEquals()
47+
{
48+
ParseBlockTest($"<a href {Environment.NewLine}= {Environment.NewLine}'@Foo' />",
49+
new MarkupBlock(
50+
new MarkupTagBlock(
51+
Factory.Markup("<a"),
52+
new MarkupBlock(new AttributeBlockChunkGenerator(name: "href", prefix: new LocationTagged<string>($" href {Environment.NewLine}= {Environment.NewLine}'", 2, 0, 2), suffix: new LocationTagged<string>("'", 19, 2, 5)),
53+
Factory.Markup($" href {Environment.NewLine}= {Environment.NewLine}'").With(SpanChunkGenerator.Null),
54+
new MarkupBlock(new DynamicAttributeBlockChunkGenerator(new LocationTagged<string>(string.Empty, 15, 2, 1), 15, 2, 1),
55+
new ExpressionBlock(
56+
Factory.CodeTransition(),
57+
Factory.Code("Foo")
58+
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
59+
.Accepts(AcceptedCharacters.NonWhiteSpace))),
60+
Factory.Markup("'").With(SpanChunkGenerator.Null)),
61+
Factory.Markup(" />").Accepts(AcceptedCharacters.None))));
62+
}
63+
4564
[Fact]
4665
public void MultiPartLiteralAttribute()
4766
{
@@ -343,12 +362,12 @@ public void ConditionalAttributesDoNotCreateExtraDataForEntirelyLiteralAttribute
343362
[Fact]
344363
public void ConditionalAttributesAreDisabledForDataAttributesInBlock()
345364
{
346-
ParseBlockTest("<span data-foo='@foo'></span>",
365+
ParseBlockTest("<span data-foo = '@foo'></span>",
347366
new MarkupBlock(
348367
new MarkupTagBlock(
349368
Factory.Markup("<span"),
350369
new MarkupBlock(
351-
Factory.Markup(" data-foo='"),
370+
Factory.Markup(" data-foo = '"),
352371
new ExpressionBlock(
353372
Factory.CodeTransition(),
354373
Factory.Code("foo")
@@ -363,19 +382,18 @@ public void ConditionalAttributesAreDisabledForDataAttributesInBlock()
363382
[Fact]
364383
public void ConditionalAttributesAreDisabledForDataAttributesInDocument()
365384
{
366-
ParseDocumentTest("<span data-foo='@foo'></span>",
385+
ParseDocumentTest("<span data-foo=@foo ></span>",
367386
new MarkupBlock(
368387
new MarkupTagBlock(
369388
Factory.Markup("<span"),
370389
new MarkupBlock(
371-
Factory.Markup(" data-foo='"),
390+
Factory.Markup(" data-foo="),
372391
new ExpressionBlock(
373392
Factory.CodeTransition(),
374393
Factory.Code("foo")
375394
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
376-
.Accepts(AcceptedCharacters.NonWhiteSpace)),
377-
Factory.Markup("'")),
378-
Factory.Markup(">")),
395+
.Accepts(AcceptedCharacters.NonWhiteSpace))),
396+
Factory.Markup(" >")),
379397
new MarkupTagBlock(
380398
Factory.Markup("</span>"))));
381399
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#pragma checksum "TagHelpersWithWeirdlySpacedAttributes.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "28d049638bc8b665f1a0b5fa1e3704261e413e5a"
2+
namespace TestOutput
3+
{
4+
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
5+
using System;
6+
using System.Threading.Tasks;
7+
8+
public class TagHelpersWithWeirdlySpacedAttributes
9+
{
10+
#line hidden
11+
#pragma warning disable 0414
12+
private TagHelperContent __tagHelperStringValueBuffer = null;
13+
#pragma warning restore 0414
14+
private TagHelperExecutionContext __tagHelperExecutionContext = null;
15+
private TagHelperRunner __tagHelperRunner = null;
16+
private TagHelperScopeManager __tagHelperScopeManager = new TagHelperScopeManager();
17+
private PTagHelper __PTagHelper = null;
18+
private InputTagHelper __InputTagHelper = null;
19+
private InputTagHelper2 __InputTagHelper2 = null;
20+
#line hidden
21+
public TagHelpersWithWeirdlySpacedAttributes()
22+
{
23+
}
24+
25+
#pragma warning disable 1998
26+
public override async Task ExecuteAsync()
27+
{
28+
__tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner();
29+
Instrumentation.BeginContext(33, 2, true);
30+
WriteLiteral("\r\n");
31+
Instrumentation.EndContext();
32+
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => {
33+
Instrumentation.BeginContext(84, 11, true);
34+
WriteLiteral("Body of Tag");
35+
Instrumentation.EndContext();
36+
}
37+
, StartTagHelperWritingScope, EndTagHelperWritingScope);
38+
__PTagHelper = CreateTagHelper<PTagHelper>();
39+
__tagHelperExecutionContext.Add(__PTagHelper);
40+
__tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("Hello World"));
41+
#line 6 "TagHelpersWithWeirdlySpacedAttributes.cshtml"
42+
__PTagHelper.Age = 1337;
43+
44+
#line default
45+
#line hidden
46+
__tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age);
47+
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
48+
Instrumentation.BeginContext(35, 64, false);
49+
await WriteTagHelperAsync(__tagHelperExecutionContext);
50+
Instrumentation.EndContext();
51+
__tagHelperExecutionContext = __tagHelperScopeManager.End();
52+
Instrumentation.BeginContext(99, 4, true);
53+
WriteLiteral("\r\n\r\n");
54+
Instrumentation.EndContext();
55+
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", TagMode.SelfClosing, "test", async() => {
56+
}
57+
, StartTagHelperWritingScope, EndTagHelperWritingScope);
58+
__InputTagHelper = CreateTagHelper<InputTagHelper>();
59+
__tagHelperExecutionContext.Add(__InputTagHelper);
60+
__InputTagHelper2 = CreateTagHelper<InputTagHelper2>();
61+
__tagHelperExecutionContext.Add(__InputTagHelper2);
62+
__InputTagHelper.Type = "text";
63+
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
64+
__InputTagHelper2.Type = __InputTagHelper.Type;
65+
__tagHelperExecutionContext.AddHtmlAttribute("data-content", Html.Raw("hello"));
66+
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
67+
Instrumentation.BeginContext(103, 45, false);
68+
await WriteTagHelperAsync(__tagHelperExecutionContext);
69+
Instrumentation.EndContext();
70+
__tagHelperExecutionContext = __tagHelperScopeManager.End();
71+
}
72+
#pragma warning restore 1998
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@addTagHelper "something, nice"
2+
3+
<p
4+
class
5+
=
6+
"Hello World" age =1337
7+
>Body of Tag</p>
8+
9+
<input type = 'text' data-content= "hello" />

0 commit comments

Comments
 (0)