Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #359 from thecodejunkie/capturedparametersdecoding…
Browse files Browse the repository at this point in the history
…-351

Removed url decoding in route matcher
  • Loading branch information
grumpydev committed Oct 25, 2011
2 parents 5a070c5 + f3e156e commit 819f03a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,13 @@ public void Should_allow_regex_in_route_definition_and_return_negative_result_wh
}

[Fact]
public void Should_properly_handle_uri_escaped_route_parameters_that_were_matched()
public void Should_not_url_decode_captured_parameters()
{
// Given
const string parameter = "baa ram ewe{}";
var escapedParameter = Uri.EscapeUriString(parameter);
var parameter = Uri.EscapeUriString("baa ram ewe{}");

// When
var results = this.matcher.Match("/foo/" + escapedParameter, "/foo/{bar}");
var results = this.matcher.Match("/foo/" + parameter, "/foo/{bar}");

//Then
((string)results.Parameters["bar"]).ShouldEqual(parameter);
Expand Down
15 changes: 9 additions & 6 deletions src/Nancy/Routing/DefaultRoutePatternMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Globalization;
using System.Text.RegularExpressions;
using Nancy.Extensions;
using Nancy.Helpers;

/// <summary>
/// Default implementation of a route pattern matcher.
Expand All @@ -17,10 +16,14 @@ public class DefaultRoutePatternMatcher : IRoutePatternMatcher

public IRoutePatternMatchResult Match(string requestedPath, string routePath)
{
var routePathPattern = this.matcherCache.GetOrAdd(routePath, (s) => BuildRegexMatcher(routePath));
var routePathPattern =
this.matcherCache.GetOrAdd(routePath, s => BuildRegexMatcher(routePath));

requestedPath = TrimTrailingSlashFromRequestedPath(requestedPath);
var match = routePathPattern.Match(HttpUtility.UrlDecode(requestedPath));
requestedPath =
TrimTrailingSlashFromRequestedPath(requestedPath);

var match =
routePathPattern.Match(requestedPath);

return new RoutePatternMatchResult(
match.Success,
Expand Down Expand Up @@ -55,9 +58,9 @@ private static DynamicDictionary GetParameters(Regex regex, GroupCollection grou
{
dynamic data = new DynamicDictionary();

for (int i = 1; i <= groups.Count; i++)
for (var i = 1; i <= groups.Count; i++)
{
data[regex.GroupNameFromNumber(i)] = Uri.UnescapeDataString(groups[i].Value);
data[regex.GroupNameFromNumber(i)] = groups[i].Value;
}

return data;
Expand Down

0 comments on commit 819f03a

Please sign in to comment.