This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Link header non-ASCII characters issue (#2903)
- Loading branch information
1 parent
68e0b9f
commit de458a9
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
43 changes: 43 additions & 0 deletions
43
test/Nancy.Tests/Unit/Responses/Negotiation/DefaultResponseNegotiatorFixture.cs
This file contains 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,43 @@ | ||
namespace Nancy.Tests.Unit.Responses.Negotiation | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Nancy.Responses.Negotiation; | ||
|
||
using Xunit; | ||
|
||
public class DefaultResponseNegotiatorFixture | ||
{ | ||
[Fact] | ||
public void Should_encode_URL_in_Link_response_header() | ||
{ | ||
// Given | ||
var negotiator = new DefaultResponseNegotiatorWrapper(); | ||
var requestUrl = new Uri("http://localhost:80/george-å"); | ||
var range = new MediaRange("application/vnd.nancy"); | ||
var linkProcessor = new KeyValuePair<string, MediaRange>("nancy", range); | ||
|
||
// When | ||
var linkHeader = negotiator.CreateLinkHeaderWrapper(requestUrl, new[] { linkProcessor }, null); | ||
|
||
// Then | ||
Assert.DoesNotContain("å", linkHeader, StringComparison.InvariantCultureIgnoreCase); | ||
Assert.Contains("%C3%A5", linkHeader, StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
private class DefaultResponseNegotiatorWrapper : DefaultResponseNegotiator | ||
{ | ||
public DefaultResponseNegotiatorWrapper() | ||
: base(Enumerable.Empty<IResponseProcessor>(), null) | ||
{ | ||
} | ||
|
||
public string CreateLinkHeaderWrapper(Url requestUrl, IEnumerable<KeyValuePair<string, MediaRange>> linkProcessors, string existingLinkHeader) | ||
{ | ||
return base.CreateLinkHeader(requestUrl, linkProcessors, existingLinkHeader); | ||
} | ||
} | ||
} | ||
} |