Fix ReplaceTokens bug in AttributeRouteModel (#6957)
This commit is contained in:
parent
d4c55df8f4
commit
8f6853e155
|
|
@ -231,6 +231,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
var state = TemplateParserState.Plaintext;
|
var state = TemplateParserState.Plaintext;
|
||||||
|
|
||||||
int? tokenStart = null;
|
int? tokenStart = null;
|
||||||
|
var scope = 0;
|
||||||
|
|
||||||
// We'll run the loop one extra time with 'null' to detect the end of the string.
|
// We'll run the loop one extra time with 'null' to detect the end of the string.
|
||||||
for (var i = 0; i <= template.Length; i++)
|
for (var i = 0; i <= template.Length; i++)
|
||||||
|
|
@ -241,6 +242,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
case TemplateParserState.Plaintext:
|
case TemplateParserState.Plaintext:
|
||||||
if (c == '[')
|
if (c == '[')
|
||||||
{
|
{
|
||||||
|
scope++;
|
||||||
state = TemplateParserState.SeenLeft;
|
state = TemplateParserState.SeenLeft;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -321,6 +323,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
}
|
}
|
||||||
else if (c == ']')
|
else if (c == ']')
|
||||||
{
|
{
|
||||||
|
--scope;
|
||||||
state = TemplateParserState.InsideToken | TemplateParserState.SeenRight;
|
state = TemplateParserState.InsideToken | TemplateParserState.SeenRight;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -353,7 +356,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
case TemplateParserState.InsideToken | TemplateParserState.SeenRight:
|
case TemplateParserState.InsideToken | TemplateParserState.SeenRight:
|
||||||
if (c == ']')
|
if (c == ']' && scope == 0)
|
||||||
{
|
{
|
||||||
// This is an escaped right-bracket
|
// This is an escaped right-bracket
|
||||||
state = TemplateParserState.InsideToken;
|
state = TemplateParserState.InsideToken;
|
||||||
|
|
@ -402,6 +405,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
state = TemplateParserState.Plaintext;
|
state = TemplateParserState.Plaintext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope = 0;
|
||||||
tokenStart = null;
|
tokenStart = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -590,6 +590,83 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
},
|
},
|
||||||
"Home/Index/{id}"
|
"Home/Index/{id}"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[action]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[Index]/{id}"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[action]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[[Index]]/{id}"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[[[action]]]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[[[Index]]]/{id}"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[action]]]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[[Index]]]/{id}"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[[[action]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[[[Index]]/{id}"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[action]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[Index]]/{id}"
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[[[action]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Home/[[[Index]/{id}"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -655,6 +732,61 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase),
|
||||||
"An empty replacement token ('[]') is not allowed.",
|
"An empty replacement token ('[]') is not allowed.",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[action]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Token delimiters ('[', ']') are imbalanced.",
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[action]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Token delimiters ('[', ']') are imbalanced.",
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[action]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Token delimiters ('[', ']') are imbalanced.",
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[[[action]]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Token delimiters ('[', ']') are imbalanced.",
|
||||||
|
};
|
||||||
|
|
||||||
|
yield return new object[]
|
||||||
|
{
|
||||||
|
"[controller]/[[[[[[action]]]]]]]/{id}",
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ "controller", "Home" },
|
||||||
|
{ "action", "Index" }
|
||||||
|
},
|
||||||
|
"Token delimiters ('[', ']') are imbalanced.",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue