- Modified `UrlResolutionTagHelper` to utilize new CSS selector attributes to restrict when it applies. It now only appies to tags that have their values starting with `~/`.
- `UrlResolutionTagHelper` no longer applies to dynamic content such as `href="@SomethingResultingInTildaSlash"`.
- Updated tests to reflect new behavior.
This commit is contained in:
N. Taylor Mullen 2016-03-07 17:29:00 -08:00
parent f3740b2196
commit 5612ca845f
3 changed files with 36 additions and 36 deletions

View File

@ -21,35 +21,35 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
/// <remarks>Resolves URLs starting with '~/' (relative to the application's 'webroot' setting) that are not /// <remarks>Resolves URLs starting with '~/' (relative to the application's 'webroot' setting) that are not
/// targeted by other <see cref="ITagHelper"/>s. Runs prior to other <see cref="ITagHelper"/>s to ensure /// targeted by other <see cref="ITagHelper"/>s. Runs prior to other <see cref="ITagHelper"/>s to ensure
/// application-relative URLs are resolved.</remarks> /// application-relative URLs are resolved.</remarks>
[HtmlTargetElement("*", Attributes = "itemid")] [HtmlTargetElement("*", Attributes = "[itemid^='~/']")]
[HtmlTargetElement("a", Attributes = "href")] [HtmlTargetElement("a", Attributes = "[href^='~/']")]
[HtmlTargetElement("applet", Attributes = "archive")] [HtmlTargetElement("applet", Attributes = "[archive^='~/']")]
[HtmlTargetElement("area", Attributes = "href", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("area", Attributes = "[href^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("audio", Attributes = "src")] [HtmlTargetElement("audio", Attributes = "[src^='~/']")]
[HtmlTargetElement("base", Attributes = "href", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("base", Attributes = "[href^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("blockquote", Attributes = "cite")] [HtmlTargetElement("blockquote", Attributes = "[cite^='~/']")]
[HtmlTargetElement("button", Attributes = "formaction")] [HtmlTargetElement("button", Attributes = "[formaction^='~/']")]
[HtmlTargetElement("del", Attributes = "cite")] [HtmlTargetElement("del", Attributes = "[cite^='~/']")]
[HtmlTargetElement("embed", Attributes = "src", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("embed", Attributes = "[src^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("form", Attributes = "action")] [HtmlTargetElement("form", Attributes = "[action^='~/']")]
[HtmlTargetElement("html", Attributes = "manifest")] [HtmlTargetElement("html", Attributes = "[manifest^='~/']")]
[HtmlTargetElement("iframe", Attributes = "src")] [HtmlTargetElement("iframe", Attributes = "[src^='~/']")]
[HtmlTargetElement("img", Attributes = "src", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("img", Attributes = "[src^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "srcset", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("img", Attributes = "[srcset^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("input", Attributes = "src", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("input", Attributes = "[src^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("input", Attributes = "formaction", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("input", Attributes = "[formaction^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("ins", Attributes = "cite")] [HtmlTargetElement("ins", Attributes = "[cite^='~/']")]
[HtmlTargetElement("link", Attributes = "href", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("link", Attributes = "[href^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("menuitem", Attributes = "icon")] [HtmlTargetElement("menuitem", Attributes = "[icon^='~/']")]
[HtmlTargetElement("object", Attributes = "archive")] [HtmlTargetElement("object", Attributes = "[archive^='~/']")]
[HtmlTargetElement("object", Attributes = "data")] [HtmlTargetElement("object", Attributes = "[data^='~/']")]
[HtmlTargetElement("q", Attributes = "cite")] [HtmlTargetElement("q", Attributes = "[cite^='~/']")]
[HtmlTargetElement("script", Attributes = "src")] [HtmlTargetElement("script", Attributes = "[src^='~/']")]
[HtmlTargetElement("source", Attributes = "src", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("source", Attributes = "[src^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("source", Attributes = "srcset", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("source", Attributes = "[srcset^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("track", Attributes = "src", TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("track", Attributes = "[src^='~/']", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("video", Attributes = "src")] [HtmlTargetElement("video", Attributes = "[src^='~/']")]
[HtmlTargetElement("video", Attributes = "poster")] [HtmlTargetElement("video", Attributes = "[poster^='~/']")]
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
public class UrlResolutionTagHelper : TagHelper public class UrlResolutionTagHelper : TagHelper
{ {

View File

@ -7,13 +7,13 @@
<a href="HtmlEncode[[/]]Person">Person</a> <a href="HtmlEncode[[/]]Person">Person</a>
<area href="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" alt="Url stuff"> <area href="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" alt="Url stuff">
<link href="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]/CSS" rel="stylesheet"> <link href="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]/CSS" rel="stylesheet">
<video poster="HtmlEncode[[~/SomeUrl]]" src="HtmlEncode[[~/SomeUrl]]/HtmlEncode[[video]]" /> <video poster=HtmlEncode[[~/SomeUrl]] src='HtmlEncode[[~/SomeUrl]]/HtmlEncode[[video]]' />
<audio src="HtmlEncode[[~/SomeUrl]]"> <audio src="HtmlEncode[[~/SomeUrl]]">
<source src="HtmlEncode[[/]]Person" srcset="HtmlEncode[[/]]Person"> <source src="HtmlEncode[[/]]Person" srcset="HtmlEncode[[/]]Person">
<track src="HtmlEncode[[/]]emailHtmlEncode[[~/SomeUrl]]"> <track src="HtmlEncode[[/]]emailHtmlEncode[[~/SomeUrl]]">
</audio> </audio>
<embed src="HtmlEncode[[/]]email@dyanmicUrl"> <embed src="HtmlEncode[[/]]email@dyanmicUrl">
<iframe src="HtmlEncode[[~/SomeUrl]]" /> <iframe src=HtmlEncode[[~/SomeUrl]] />
<img src="HtmlEncode[[/]]HtmlEncode[[John Doe]]" srcset="HtmlEncode[[/]]HtmlEncode[[John Doe]]"> <img src="HtmlEncode[[/]]HtmlEncode[[John Doe]]" srcset="HtmlEncode[[/]]HtmlEncode[[John Doe]]">
<script src="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]/JS"></script> <script src="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]/JS"></script>
<input src="HtmlEncode[[/]]/Person" itemscope itemid="HtmlEncode[[/]]Person" formaction="HtmlEncode[[~/SomeUrl]]"> <input src="HtmlEncode[[/]]/Person" itemscope itemid="HtmlEncode[[/]]Person" formaction="HtmlEncode[[~/SomeUrl]]">
@ -27,7 +27,7 @@
<menuitem icon="HtmlEncode[[/]]Person" /> <menuitem icon="HtmlEncode[[/]]Person" />
</menu> </menu>
<object data="HtmlEncode[[/]]Person" archive="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" data="HtmlEncode[[/]]Person" archive="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" /> <object data="HtmlEncode[[/]]Person" archive="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" data="HtmlEncode[[/]]Person" archive="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" />
<object archive="HtmlEncode[[/]]Person/HtmlEncode[[John Doe]]" /> <object archive="~/Person/HtmlEncode[[John Doe]] " />
<applet archive="HtmlEncode[[/]]A+Really(Crazy),Url.Is:This/HtmlEncode[[John Doe]]/Detail" /> <applet archive="HtmlEncode[[/]]A+Really(Crazy),Url.Is:This/HtmlEncode[[John Doe]]/Detail" />
</body> </body>
</html> </html>

View File

@ -7,13 +7,13 @@
<a href="/Person">Person</a> <a href="/Person">Person</a>
<area href="/Person/John Doe" alt="Url stuff"> <area href="/Person/John Doe" alt="Url stuff">
<link href="/Person/John Doe/CSS" rel="stylesheet"> <link href="/Person/John Doe/CSS" rel="stylesheet">
<video poster="/SomeUrl" src="/SomeUrl/video" /> <video poster=~/SomeUrl src='~/SomeUrl/video' />
<audio src="/SomeUrl"> <audio src="~/SomeUrl">
<source src="/Person" srcset="/Person"> <source src="/Person" srcset="/Person">
<track src="/email~/SomeUrl"> <track src="/email~/SomeUrl">
</audio> </audio>
<embed src="/email@dyanmicUrl"> <embed src="/email@dyanmicUrl">
<iframe src="/SomeUrl" /> <iframe src=~/SomeUrl />
<img src="/John Doe" srcset="/John Doe"> <img src="/John Doe" srcset="/John Doe">
<script src="/Person/John Doe/JS"></script> <script src="/Person/John Doe/JS"></script>
<input src="//Person" itemscope itemid="/Person" formaction="/SomeUrl"> <input src="//Person" itemscope itemid="/Person" formaction="/SomeUrl">
@ -27,7 +27,7 @@
<menuitem icon="/Person" /> <menuitem icon="/Person" />
</menu> </menu>
<object data="/Person" archive="/Person/John Doe" data="/Person" archive="/Person/John Doe" /> <object data="/Person" archive="/Person/John Doe" data="/Person" archive="/Person/John Doe" />
<object archive="/Person/John Doe" /> <object archive="~/Person/John Doe " />
<applet archive="/A+Really(Crazy),Url.Is:This/John Doe/Detail" /> <applet archive="/A+Really(Crazy),Url.Is:This/John Doe/Detail" />
</body> </body>
</html> </html>