Merge pull request #1963 from umbraco/temp-deploy-324

deploy-324 - fix udi encoding
This commit is contained in:
Mikkel Holck Madsen
2017-05-26 13:14:29 +02:00
committed by GitHub
4 changed files with 40 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Linq;
namespace Umbraco.Core
{
@@ -20,7 +21,7 @@ namespace Umbraco.Core
/// <param name="entityType">The entity type part of the udi.</param>
/// <param name="id">The string id part of the udi.</param>
public StringUdi(string entityType, string id)
: base(entityType, "umb://" + entityType + "/" + Uri.EscapeUriString(id))
: base(entityType, "umb://" + entityType + "/" + EscapeUriString(id))
{
Id = id;
}
@@ -35,6 +36,19 @@ namespace Umbraco.Core
Id = Uri.UnescapeDataString(uriValue.AbsolutePath.TrimStart('/'));
}
private static string EscapeUriString(string s)
{
// Uri.EscapeUriString preserves / but also [ and ] which is bad
// Uri.EscapeDataString does not preserve / which is bad
// reserved = : / ? # [ ] @ ! $ & ' ( ) * + , ; =
// unreserved = alpha digit - . _ ~
// we want to preserve the / and the unreserved
// so...
return string.Join("/", s.Split('/').Select(Uri.EscapeDataString));
}
/// <summary>
/// Converts the string representation of an entity identifier into the equivalent StringUdi instance.
/// </summary>

View File

@@ -79,6 +79,7 @@
</system.data>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation defaultLanguage="c#" debug="true" batch="false" targetFramework="4.0"></compilation>
<machineKey validationKey="5E7B955FCE36F5F2A867C2A0D85DC61E7FEA9E15F1561E8386F78BFE9EE23FF18B21E6A44AA17300B3B9D5DBEB37AA61A2C73884A5BBEDA6D3B14BA408A7A8CD" decryptionKey="116B853D031219E404E088FCA0986D6CF2DFA77E1957B59FCC9404B8CA3909A1" validation="SHA1" decryption="AES" />
<!--<trust level="Medium" originUrl=".*"/>-->

View File

@@ -59,6 +59,29 @@ namespace Umbraco.Tests
Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/path%20to/this%20is%20a%20test.xyz", udi3.ToString());
}
[Test]
public void StringEncodingTest2()
{
// reserved = : / ? # [ ] @ ! $ & ' ( ) * + , ; =
// unreserved = alpha digit - . _ ~
Assert.AreEqual("%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2B%2C%3B%3D.-_~%25", Uri.EscapeDataString(":/?#[]@!$&'()+,;=.-_~%"));
Assert.AreEqual(":/?#[]@!$&'()+,;=.-_~%25", Uri.EscapeUriString(":/?#[]@!$&'()+,;=.-_~%"));
// we cannot have reserved chars at random places
// we want to keep the / in string udis
var r = string.Join("/", "path/to/View[1].cshtml".Split('/').Select(Uri.EscapeDataString));
Assert.AreEqual("path/to/View%5B1%5D.cshtml", r);
Assert.IsTrue(Uri.IsWellFormedUriString("umb://partial-view-macro/" + r, UriKind.Absolute));
// with the proper fix in StringUdi this should work:
var udi1 = new StringUdi("partial-view-macro", "path/to/View[1].cshtml");
Assert.AreEqual("umb://partial-view-macro/path/to/View%5B1%5D.cshtml", udi1.ToString());
var udi2 = Udi.Parse("umb://partial-view-macro/path/to/View%5B1%5D.cshtml");
Assert.AreEqual("path/to/View[1].cshtml", ((StringUdi) udi2).Id);
}
[Test]
public void GuidEntityCtorTest()
{

View File

@@ -21,6 +21,7 @@
<package id="Moq" version="4.1.1309.0919" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
<package id="NUnit" version="2.6.2" targetFramework="net45" />
<package id="NUnitTestAdapter" version="2.1.1" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.32.0" targetFramework="net45" />
<package id="semver" version="1.1.2" targetFramework="net45" />