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

Commit

Permalink
[Fixes #183] Fix error with double transition in value attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaybhargavb committed May 11, 2015
1 parent 89b5f5b commit 977f001
Show file tree
Hide file tree
Showing 7 changed files with 548 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs
Expand Up @@ -149,7 +149,7 @@ public override void ParseBlock()
var current = CurrentSymbol;
if (At(CSharpSymbolType.StringLiteral) && CurrentSymbol.Content.Length > 0 && CurrentSymbol.Content[0] == SyntaxConstants.TransitionCharacter)
{
Tuple<CSharpSymbol, CSharpSymbol> split = Language.SplitSymbol(CurrentSymbol, 1, CSharpSymbolType.Transition);
var split = Language.SplitSymbol(CurrentSymbol, 1, CSharpSymbolType.Transition);
current = split.Item1;
Context.Source.Position = split.Item2.Start.AbsoluteIndex;
NextToken();
Expand Down
44 changes: 29 additions & 15 deletions src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs
Expand Up @@ -316,7 +316,7 @@ private bool CData()
var matched = RemoveTag(tags, tagName, tagStart);

if (tags.Count == 0 &&
// Note tagName may contain a '!' escape character. This ensures </!text> doesn't match here.
// Note tagName may contain a '!' escape character. This ensures </!text> doesn't match here.
// </!text> tags are treated like any other escaped HTML end tag.
string.Equals(tagName, SyntaxConstants.TextTagName, StringComparison.OrdinalIgnoreCase) &&
matched)
Expand Down Expand Up @@ -491,7 +491,7 @@ private void BeforeAttribute()
private void AttributePrefix(IEnumerable<HtmlSymbol> whitespace, IEnumerable<HtmlSymbol> nameSymbols)
{
// First, determine if this is a 'data-' attribute (since those can't use conditional attributes)
LocationTagged<string> name = nameSymbols.GetContent(Span.Start);
var name = nameSymbols.GetContent(Span.Start);
var attributeCanBeConditional = !name.Value.StartsWith("data-", StringComparison.OrdinalIgnoreCase);

// Accept the whitespace and name
Expand All @@ -507,7 +507,7 @@ private void AttributePrefix(IEnumerable<HtmlSymbol> whitespace, IEnumerable<Htm
}

// We now have the prefix: (i.e. ' foo="')
LocationTagged<string> prefix = Span.GetContent();
var prefix = Span.GetContent();

if (attributeCanBeConditional)
{
Expand All @@ -521,7 +521,7 @@ private void AttributePrefix(IEnumerable<HtmlSymbol> whitespace, IEnumerable<Htm
}

// Capture the suffix
LocationTagged<string> suffix = new LocationTagged<string>(string.Empty, CurrentLocation);
var suffix = new LocationTagged<string>(string.Empty, CurrentLocation);
if (quote != HtmlSymbolType.Unknown && At(quote))
{
suffix = CurrentSymbol.GetContent();
Expand Down Expand Up @@ -558,19 +558,33 @@ private void AttributeValue(HtmlSymbolType quote)

if (At(HtmlSymbolType.Transition))
{
var valueStart = CurrentLocation;
PutCurrentBack();
if (NextIs(HtmlSymbolType.Transition))
{
// Render a single "@" in place of "@@".
var transition = CurrentSymbol;
NextToken();
Output(SpanKind.Markup);
Accept(transition);
Span.CodeGenerator = SpanCodeGenerator.Null;
Output(SpanKind.Markup);
AcceptAndMoveNext();
}
else
{
var valueStart = CurrentLocation;
PutCurrentBack();

// Output the prefix but as a null-span. DynamicAttributeBlockCodeGenerator will render it
Span.CodeGenerator = SpanCodeGenerator.Null;
// Output the prefix but as a null-span. DynamicAttributeBlockCodeGenerator will render it
Span.CodeGenerator = SpanCodeGenerator.Null;

// Dynamic value, start a new block and set the code generator
using (Context.StartBlock(BlockType.Markup))
{
Context.CurrentBlock.CodeGenerator =
new DynamicAttributeBlockCodeGenerator(prefix.GetContent(prefixStart), valueStart);
// Dynamic value, start a new block and set the code generator
using (Context.StartBlock(BlockType.Markup))
{
Context.CurrentBlock.CodeGenerator =
new DynamicAttributeBlockCodeGenerator(prefix.GetContent(prefixStart), valueStart);

OtherParserBlock();
OtherParserBlock();
}
}
}
else if (At(HtmlSymbolType.Text) &&
Expand Down Expand Up @@ -719,7 +733,7 @@ private bool StartTag(Stack<Tuple<HtmlSymbol, SourceLocation>> tags, IDisposable
Tuple<HtmlSymbol, SourceLocation> tag = Tuple.Create(tagName, _lastTagStart);

if (tags.Count == 0 &&
// Note tagName may contain a '!' escape character. This ensures <!text> doesn't match here.
// Note tagName may contain a '!' escape character. This ensures <!text> doesn't match here.
// <!text> tags are treated like any other escaped HTML start tag.
string.Equals(tag.Item1.Content, SyntaxConstants.TextTagName, StringComparison.OrdinalIgnoreCase))
{
Expand Down
7 changes: 3 additions & 4 deletions test/Microsoft.AspNet.Razor.Test/Framework/ParserTestBase.cs
Expand Up @@ -277,15 +277,14 @@ public static void EvaluateParseTree(Block actualRoot, Block expectedRoot)
// Evaluate the result
var collector = new ErrorCollector();

// Link all the nodes
expectedRoot.LinkNodes();

if (expectedRoot == null)
{
Assert.Null(actualRoot);
}
else
{
// Link all the nodes
expectedRoot.LinkNodes();
Assert.NotNull(actualRoot);
EvaluateSyntaxTreeNode(collector, actualRoot, expectedRoot);
if (collector.Success)
Expand Down Expand Up @@ -412,7 +411,7 @@ private static void EvaluateTagHelperBlock(ErrorCollector collector, TagHelperBl
actual.TagName,
actual.SelfClosing);
}

var expectedAttributes = expected.Attributes.GetEnumerator();
var actualAttributes = actual.Attributes.GetEnumerator();

Expand Down

0 comments on commit 977f001

Please sign in to comment.