This repository was archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
Add HttpReqeuest GetEncodedUrl and GetDecodedUrl extensions. #359
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/Microsoft.AspNet.Http.Extensions.Tests/UriHelperTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNet.Http.Internal; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNet.Http.Extensions | ||
{ | ||
public class UriHelperTests | ||
{ | ||
[Fact] | ||
public void EncodeEmptyPartialUrl() | ||
{ | ||
var result = UriHelper.Encode(); | ||
|
||
Assert.Equal("/", result); | ||
} | ||
|
||
[Fact] | ||
public void EncodePartialUrl() | ||
{ | ||
var result = UriHelper.Encode(new PathString("/un?escaped/base"), new PathString("/un?escaped"), | ||
new QueryString("?name=val%23ue"), new FragmentString("#my%20value")); | ||
|
||
Assert.Equal("/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result); | ||
} | ||
|
||
[Fact] | ||
public void EncodeEmptyFullUrl() | ||
{ | ||
var result = UriHelper.Encode("http", new HostString(string.Empty)); | ||
|
||
Assert.Equal("http:///", result); | ||
} | ||
|
||
[Fact] | ||
public void EncodeFullUrl() | ||
{ | ||
var result = UriHelper.Encode("http", new HostString("my.HoΨst:80"), new PathString("/un?escaped/base"), new PathString("/un?escaped"), | ||
new QueryString("?name=val%23ue"), new FragmentString("#my%20value")); | ||
|
||
Assert.Equal("http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result); | ||
} | ||
|
||
[Fact] | ||
public void GetEncodedUrlFromRequest() | ||
{ | ||
var request = new DefaultHttpContext().Request; | ||
request.Scheme = "http"; | ||
request.Host = new HostString("my.HoΨst:80"); | ||
request.PathBase = new PathString("/un?escaped/base"); | ||
request.Path = new PathString("/un?escaped"); | ||
request.QueryString = new QueryString("?name=val%23ue"); | ||
|
||
Assert.Equal("http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue", request.GetEncodedUrl()); | ||
} | ||
|
||
[Fact] | ||
public void GetDisplayUrlFromRequest() | ||
{ | ||
var request = new DefaultHttpContext().Request; | ||
request.Scheme = "http"; | ||
request.Host = new HostString("my.HoΨst:80"); | ||
request.PathBase = new PathString("/un?escaped/base"); | ||
request.Path = new PathString("/un?escaped"); | ||
request.QueryString = new QueryString("?name=val%23ue"); | ||
|
||
Assert.Equal("http://my.hoψst:80/un?escaped/base/un?escaped?name=val%23ue", request.GetDisplayUrl()); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does all this concatenation work when some sections are missing? E.g. no query string or empty path etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Added tests for empty params.