Skip to content

Commit

Permalink
fix($urlMatcherFactory): fix encoding slashes in params
Browse files Browse the repository at this point in the history
Closes #1119
  • Loading branch information
christopherthielen committed Nov 17, 2014
1 parent 831d812 commit 0c983a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ function $UrlMatcherFactory() {

var isCaseInsensitive = false, isStrictMode = true, defaultSquashPolicy = false;

function valToString(val) { return val != null ? val.toString().replace("/", "%2F") : val; }
function valFromString(val) { return val != null ? val.toString().replace("%2F", "/") : val; }
function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; }
function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; }
function angularEquals(left, right) { return angular.equals(left, right); }
// TODO: in 1.0, make string .is() return false if value is undefined by default.
// function regexpMatches(val) { /*jshint validthis:true */ return isDefined(val) && this.pattern.test(val); }
Expand Down
6 changes: 6 additions & 0 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ describe("UrlMatcher", function () {
expect(matcher.format(array)).toBe('/?foo=bar&foo=baz');
});

it("should encode and decode slashes in parameter values", function () {
var matcher = new UrlMatcher('/:foo');
expect(matcher.format({ foo: "/" })).toBe('/%252F');
expect(matcher.format({ foo: "//" })).toBe('/%252F%252F');
});

describe("snake-case parameters", function() {
it("should match if properly formatted", function() {
var matcher = new UrlMatcher('/users/?from&to&snake-case&snake-case-triple');
Expand Down

0 comments on commit 0c983a0

Please sign in to comment.