Use relative path instead
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
|
||||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
|
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="4.7.1" />
|
<PackageReference Include="System.Text.Json" Version="4.7.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
|
|
||||||
namespace Oqtane.Shared
|
namespace Oqtane.Shared
|
||||||
{
|
{
|
||||||
@ -17,14 +19,29 @@ namespace Oqtane.Shared
|
|||||||
|
|
||||||
public static string NavigateUrl(string alias, string path, string parameters)
|
public static string NavigateUrl(string alias, string path, string parameters)
|
||||||
{
|
{
|
||||||
var uriBuilder = alias == string.Empty
|
if (!alias.StartsWith("/"))
|
||||||
? new UriBuilder()
|
{
|
||||||
: new UriBuilder(alias);
|
alias = $"/{alias}";
|
||||||
|
}
|
||||||
|
|
||||||
uriBuilder.Path = path;
|
if (!path.StartsWith("/"))
|
||||||
uriBuilder.Query = parameters;
|
{
|
||||||
|
path = $"/{path}";
|
||||||
|
}
|
||||||
|
|
||||||
return uriBuilder.Uri.AbsoluteUri;
|
var pathPaseValue = alias == string.Empty
|
||||||
|
? default
|
||||||
|
: new PathString(alias);
|
||||||
|
|
||||||
|
var pathValue = path == string.Empty
|
||||||
|
? default
|
||||||
|
: new PathString(path);
|
||||||
|
|
||||||
|
var queryStringValue = parameters == string.Empty
|
||||||
|
? default
|
||||||
|
: new QueryString($"?{parameters}");
|
||||||
|
|
||||||
|
return UriHelper.BuildRelative(pathPaseValue, pathValue, queryStringValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string EditUrl(string alias, string path, int moduleid, string action, string parameters)
|
public static string EditUrl(string alias, string path, int moduleid, string action, string parameters)
|
||||||
|
@ -6,22 +6,16 @@ namespace Oqtane.Test.Oqtane.Shared.Tests
|
|||||||
public class UtilitiesTests
|
public class UtilitiesTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("contoso", "login", "returnUrl=/admin", "http://contoso/login?returnUrl=/admin")]
|
[InlineData("contoso", "login", "returnUrl=/admin", "/contoso/login?returnUrl=/admin")]
|
||||||
[InlineData("contoso", "admin", "", "http://contoso/admin")]
|
[InlineData("contoso", "admin", "", "/contoso/admin")]
|
||||||
[InlineData("contoso", "", "pageId=4", "http://contoso/?pageId=4")]
|
[InlineData("contoso", "", "pageId=4", "/contoso/?pageId=4")]
|
||||||
[InlineData("contoso", "", "", "http://contoso/")]
|
[InlineData("contoso", "", "pageId=4&moduleId=10", "/contoso/?pageId=4&moduleId=10")]
|
||||||
[InlineData("http://contoso", "login", "returnUrl=/admin", "http://contoso/login?returnUrl=/admin")]
|
[InlineData("contoso", "", "", "/contoso/")]
|
||||||
[InlineData("http://contoso", "admin", "", "http://contoso/admin")]
|
[InlineData("", "login", "returnUrl=/admin", "/login?returnUrl=/admin")]
|
||||||
[InlineData("http://contoso", "", "pageId=4", "http://contoso/?pageId=4")]
|
[InlineData("", "admin", "", "/admin")]
|
||||||
[InlineData("http://contoso", "", "", "http://contoso/")]
|
[InlineData("", "", "pageId=4", "/?pageId=4")]
|
||||||
[InlineData("https://contoso", "login", "returnUrl=/admin", "https://contoso/login?returnUrl=/admin")]
|
[InlineData("", "", "pageId=4&moduleId=10", "/?pageId=4&moduleId=10")]
|
||||||
[InlineData("https://contoso", "admin", "", "https://contoso/admin")]
|
[InlineData("", "", "", "/")]
|
||||||
[InlineData("https://contoso", "", "pageId=4", "https://contoso/?pageId=4")]
|
|
||||||
[InlineData("https://contoso", "", "", "https://contoso/")]
|
|
||||||
[InlineData("", "login", "returnUrl=/admin", "http://localhost/login?returnUrl=/admin")]
|
|
||||||
[InlineData("", "admin", "", "http://localhost/admin")]
|
|
||||||
[InlineData("", "", "pageId=4", "http://localhost/?pageId=4")]
|
|
||||||
[InlineData("", "", "", "http://localhost/")]
|
|
||||||
public void NavigateUrlTest(string alias, string path, string parameters, string expectedUrl)
|
public void NavigateUrlTest(string alias, string path, string parameters, string expectedUrl)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
Reference in New Issue
Block a user