Fix: Index out of bounds for incomplete attribute value
- #555 - Added a unit and a code generation test
This commit is contained in:
parent
adfa02de90
commit
bc103fcaa4
|
|
@ -215,34 +215,29 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
||||||
|
|
||||||
// The coming symbols will either be a quote or value (in the case that the value is unquoted).
|
// The coming symbols will either be a quote or value (in the case that the value is unquoted).
|
||||||
|
|
||||||
// TODO: Handle malformed tags, if there's an '=' then there MUST be a value.
|
|
||||||
// https://github.com/aspnet/Razor/issues/104
|
|
||||||
|
|
||||||
SourceLocation symbolStartLocation;
|
SourceLocation symbolStartLocation;
|
||||||
|
|
||||||
// Skip the whitespace preceding the start of the attribute value.
|
// Skip the whitespace preceding the start of the attribute value.
|
||||||
var valueStartIndex = i + 1; // Start from the symbol after '='.
|
do
|
||||||
while (valueStartIndex < htmlSymbols.Length &&
|
|
||||||
(htmlSymbols[valueStartIndex].Type == HtmlSymbolType.WhiteSpace ||
|
|
||||||
htmlSymbols[valueStartIndex].Type == HtmlSymbolType.NewLine))
|
|
||||||
{
|
{
|
||||||
valueStartIndex++;
|
i++; // Start from the symbol after '='.
|
||||||
}
|
} while (i < htmlSymbols.Length &&
|
||||||
|
(htmlSymbols[i].Type == HtmlSymbolType.WhiteSpace ||
|
||||||
|
htmlSymbols[i].Type == HtmlSymbolType.NewLine));
|
||||||
|
|
||||||
// Check for attribute start values, aka single or double quote
|
// Check for attribute start values, aka single or double quote
|
||||||
if (valueStartIndex < htmlSymbols.Length && IsQuote(htmlSymbols[valueStartIndex]))
|
if (i < htmlSymbols.Length && IsQuote(htmlSymbols[i]))
|
||||||
{
|
{
|
||||||
// Move past the attribute start so we can accept the true value.
|
symbolStartLocation = htmlSymbols[i].Start;
|
||||||
valueStartIndex++;
|
|
||||||
symbolStartLocation = htmlSymbols[valueStartIndex].Start;
|
|
||||||
|
|
||||||
// If there's a start quote then there must be an end quote to be valid, skip it.
|
// If there's a start quote then there must be an end quote to be valid, skip it.
|
||||||
symbolOffset = 1;
|
symbolOffset = 1;
|
||||||
|
|
||||||
i = valueStartIndex - 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// We are at the symbol after equals. Go back to equals to ensure we don't skip past that symbol.
|
||||||
|
i--;
|
||||||
|
|
||||||
symbolStartLocation = symbol.Start;
|
symbolStartLocation = symbol.Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -920,9 +920,9 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
characterOffsetIndex: 14,
|
characterOffsetIndex: 14,
|
||||||
contentLength: 11),
|
contentLength: 11),
|
||||||
BuildLineMapping(
|
BuildLineMapping(
|
||||||
documentAbsoluteIndex: 63,
|
documentAbsoluteIndex: 62,
|
||||||
documentLineIndex: 3,
|
documentLineIndex: 3,
|
||||||
documentCharacterOffsetIndex: 27,
|
documentCharacterOffsetIndex: 26,
|
||||||
generatedAbsoluteIndex: 1289,
|
generatedAbsoluteIndex: 1289,
|
||||||
generatedLineIndex: 39,
|
generatedLineIndex: 39,
|
||||||
generatedCharacterOffsetIndex: 28,
|
generatedCharacterOffsetIndex: 28,
|
||||||
|
|
@ -935,9 +935,9 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
characterOffsetIndex: 30,
|
characterOffsetIndex: 30,
|
||||||
contentLength: 0),
|
contentLength: 0),
|
||||||
BuildLineMapping(
|
BuildLineMapping(
|
||||||
documentAbsoluteIndex: 89,
|
documentAbsoluteIndex: 88,
|
||||||
documentLineIndex: 4,
|
documentLineIndex: 4,
|
||||||
documentCharacterOffsetIndex: 13,
|
documentCharacterOffsetIndex: 12,
|
||||||
generatedAbsoluteIndex: 1789,
|
generatedAbsoluteIndex: 1789,
|
||||||
generatedLineIndex: 54,
|
generatedLineIndex: 54,
|
||||||
generatedCharacterOffsetIndex: 19,
|
generatedCharacterOffsetIndex: 19,
|
||||||
|
|
@ -1650,6 +1650,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
// Note: The baseline resource name is equivalent to the test resource name.
|
// Note: The baseline resource name is equivalent to the test resource name.
|
||||||
return new TheoryData<string, string, IEnumerable<TagHelperDescriptor>>
|
return new TheoryData<string, string, IEnumerable<TagHelperDescriptor>>
|
||||||
{
|
{
|
||||||
|
{ "IncompleteTagHelper", null, DefaultPAndInputTagHelperDescriptors },
|
||||||
{ "SingleTagHelper", null, DefaultPAndInputTagHelperDescriptors },
|
{ "SingleTagHelper", null, DefaultPAndInputTagHelperDescriptors },
|
||||||
{ "SingleTagHelperWithNewlineBeforeAttributes", null, DefaultPAndInputTagHelperDescriptors },
|
{ "SingleTagHelperWithNewlineBeforeAttributes", null, DefaultPAndInputTagHelperDescriptors },
|
||||||
{ "TagHelpersWithWeirdlySpacedAttributes", null, DefaultPAndInputTagHelperDescriptors },
|
{ "TagHelpersWithWeirdlySpacedAttributes", null, DefaultPAndInputTagHelperDescriptors },
|
||||||
|
|
|
||||||
|
|
@ -377,12 +377,21 @@ namespace Microsoft.AspNet.Razor.TagHelpers
|
||||||
return new TheoryData<string, MarkupBlock, RazorError[]>
|
return new TheoryData<string, MarkupBlock, RazorError[]>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"<p =\"false\"\" ></p>",
|
"<p class='",
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
new MarkupTagHelperBlock("p",
|
new MarkupTagHelperBlock("p",
|
||||||
new List<KeyValuePair<string, SyntaxTreeNode>>())),
|
new List<KeyValuePair<string, SyntaxTreeNode>>
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, SyntaxTreeNode>(
|
||||||
|
"class",
|
||||||
|
factory.Markup(string.Empty).With(SpanChunkGenerator.Null))
|
||||||
|
})),
|
||||||
new []
|
new []
|
||||||
{
|
{
|
||||||
|
new RazorError(
|
||||||
|
string.Format(CultureInfo.InvariantCulture, errorFormatNoCloseAngle, "p"),
|
||||||
|
new SourceLocation(1, 0, 1),
|
||||||
|
length: 1),
|
||||||
new RazorError(
|
new RazorError(
|
||||||
string.Format(CultureInfo.InvariantCulture, errorFormatUnclosed, "p"),
|
string.Format(CultureInfo.InvariantCulture, errorFormatUnclosed, "p"),
|
||||||
new SourceLocation(1, 0, 1),
|
new SourceLocation(1, 0, 1),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#pragma checksum "IncompleteTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "dba409dce3afe321d920e4e62a5701c09d7bbea8"
|
||||||
|
namespace TestOutput
|
||||||
|
{
|
||||||
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
public class IncompleteTagHelper
|
||||||
|
{
|
||||||
|
#line hidden
|
||||||
|
#pragma warning disable 0414
|
||||||
|
private TagHelperContent __tagHelperStringValueBuffer = null;
|
||||||
|
#pragma warning restore 0414
|
||||||
|
private TagHelperExecutionContext __tagHelperExecutionContext = null;
|
||||||
|
private TagHelperRunner __tagHelperRunner = null;
|
||||||
|
private TagHelperScopeManager __tagHelperScopeManager = new TagHelperScopeManager();
|
||||||
|
private PTagHelper __PTagHelper = null;
|
||||||
|
#line hidden
|
||||||
|
public IncompleteTagHelper()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable 1998
|
||||||
|
public override async Task ExecuteAsync()
|
||||||
|
{
|
||||||
|
__tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner();
|
||||||
|
Instrumentation.BeginContext(33, 2, true);
|
||||||
|
WriteLiteral("\r\n");
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => {
|
||||||
|
}
|
||||||
|
, StartTagHelperWritingScope, EndTagHelperWritingScope);
|
||||||
|
__PTagHelper = CreateTagHelper<PTagHelper>();
|
||||||
|
__tagHelperExecutionContext.Add(__PTagHelper);
|
||||||
|
__tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw(""));
|
||||||
|
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||||
|
Instrumentation.BeginContext(35, 10, false);
|
||||||
|
await WriteTagHelperAsync(__tagHelperExecutionContext);
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||||
|
}
|
||||||
|
#pragma warning restore 1998
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
@addTagHelper "something, nice"
|
||||||
|
|
||||||
|
<p class="
|
||||||
Loading…
Reference in New Issue