Skip to content

Commit 53ce7f1

Browse files
author
Edward Paget
committed
[fixed] #1148 regex for detecting trailing slashes
Fixes the regex for trailing slashes in PathUtils to not match /? if it is at the beginning of a url's query params
1 parent 50ceba2 commit 53ce7f1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

modules/PathUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var qs = require('qs');
44

55
var paramCompileMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|[*.()\[\]\\+|{}^$]/g;
66
var paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?]?)|[*]/g;
7-
var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?\/|\/\?/g;
7+
var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?\/|\/\?(?![^\/=]+=.*$)/g;
88
var queryMatcher = /\?(.*)$/;
99

1010
var _compiledPatterns = {};

modules/__tests__/PathUtils-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ describe('PathUtils.injectParams', function () {
187187
});
188188
});
189189

190+
describe('when a path has query params', function() {
191+
var pattern = '/a/:b/?c/?d=e';
192+
193+
it('should not change the query params', function() {
194+
expect(PathUtils.injectParams(pattern, {b: '123'})).toEqual('/a/123/c/?d=e');
195+
});
196+
});
197+
190198
describe('when a pattern has dynamic segments', function () {
191199
var pattern = 'comments/:id/edit';
192200

0 commit comments

Comments
 (0)