fix uQuery.GetNodeIdByUrl
This commit is contained in:
@@ -96,5 +96,12 @@ namespace Umbraco.Core
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static Uri MakeAbsolute(this Uri uri, Uri baseUri)
|
||||
{
|
||||
if (uri.IsAbsoluteUri)
|
||||
throw new ArgumentException("Uri is already absolute.", "uri");
|
||||
return new Uri(baseUri.GetLeftPart(UriPartial.Authority) + uri.GetSafeAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestCase(1175, "/home/sub-2")]
|
||||
[TestCase(1172, "/test-page")]
|
||||
|
||||
public void GetNodeIdByUrl_Not_Hiding_Top_Level(int nodeId, string url)
|
||||
public void GetNodeIdByUrl_Not_Hiding_Top_Level_Absolute(int nodeId, string url)
|
||||
{
|
||||
var routingContext = GetRoutingContext();
|
||||
Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
|
||||
@@ -56,5 +56,26 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl("http://example.com" + url));
|
||||
}
|
||||
|
||||
[TestCase(1046, "/home")]
|
||||
[TestCase(1173, "/home/sub1")]
|
||||
[TestCase(1174, "/home/sub1/sub2")]
|
||||
[TestCase(1176, "/home/sub1/sub-3")]
|
||||
[TestCase(1177, "/home/sub1/custom-sub-1")]
|
||||
[TestCase(1178, "/home/sub1/custom-sub-2")]
|
||||
[TestCase(1175, "/home/sub-2")]
|
||||
[TestCase(1172, "/test-page")]
|
||||
|
||||
public void GetNodeIdByUrl_Not_Hiding_Top_Level_Relative(int nodeId, string url)
|
||||
{
|
||||
var routingContext = GetRoutingContext();
|
||||
Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
|
||||
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl(url));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,12 +237,8 @@ namespace Umbraco.Web
|
||||
|
||||
if (!absolutePath.StartsWith("/"))
|
||||
throw new FormatException("The absolutePath specified does not start with a '/'");
|
||||
|
||||
|
||||
var url = httpContext.Request.Url;
|
||||
var port = url.Port != 80 ? (":" + url.Port) : String.Empty;
|
||||
|
||||
return new Uri(String.Format("{0}://{1}{2}{3}", url.Scheme, url.Host, port, absolutePath));
|
||||
return new Uri(absolutePath, UriKind.Relative).MakeAbsolute(httpContext.Request.Url);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Xml.XPath;
|
||||
using umbraco;
|
||||
using umbraco.NodeFactory;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace umbraco
|
||||
{
|
||||
@@ -200,7 +202,9 @@ namespace umbraco
|
||||
/// </remarks>
|
||||
public static int GetNodeIdByUrl(string url)
|
||||
{
|
||||
var uri = new System.Uri(url);
|
||||
var uri = new Uri(url, UriKind.RelativeOrAbsolute);
|
||||
if (!uri.IsAbsoluteUri)
|
||||
uri = uri.MakeAbsolute(Umbraco.Web.UmbracoContext.Current.UmbracoUrl);
|
||||
uri = Umbraco.Web.UriUtility.UriToUmbraco(uri);
|
||||
|
||||
var docreq = new Umbraco.Web.Routing.DocumentRequest(uri, Umbraco.Web.UmbracoContext.Current.RoutingContext);
|
||||
|
||||
Reference in New Issue
Block a user