Skip to content

Commit dbe3e18

Browse files
committed
✨ change lookahead to non-capturing group
1 parent 51a1955 commit dbe3e18

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function pathtoRegexp(path, keys, options) {
123123
}
124124

125125
// If the path is non-ending, match until the end or a slash.
126-
path += (end ? '$' : (path[path.length - 1] === '/' ? '' : '(?=\\/|$)'));
126+
path += (end ? '$' : (path[path.length - 1] === '/' ? '' : '(?:\/|$)'));
127127

128128
return new RegExp(path, flags);
129129
};

test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,15 @@ describe('path-to-regexp', function () {
516516

517517
it('should do non-ending matches', function () {
518518
var params = [];
519-
var m = pathToRegExp('/:test', params, { end: false }).exec('/test/route');
519+
var re = pathToRegExp('/:test', params, { end: false })
520+
var m = re.exec('/test/route');
520521

521522
assert.equal(params.length, 1);
522523
assert.equal(params[0].name, 'test');
523524
assert.equal(params[0].optional, false);
524525

525526
assert.equal(m.length, 2);
526-
assert.equal(m[0], '/test');
527+
assert.equal(m[0], '/test/');
527528
assert.equal(m[1], 'test');
528529
});
529530

@@ -558,7 +559,7 @@ describe('path-to-regexp', function () {
558559
m = re.exec('/route/test');
559560

560561
assert.equal(m.length, 1);
561-
assert.equal(m[0], '/route');
562+
assert.equal(m[0], '/route/');
562563

563564
m = re.exec('/route');
564565

@@ -568,7 +569,7 @@ describe('path-to-regexp', function () {
568569
m = re.exec('/route//');
569570

570571
assert.equal(m.length, 1);
571-
assert.equal(m[0], '/route/');
572+
assert.equal(m[0], '/route//');
572573
});
573574

574575
it('should match trailing slashing in non-ending strict mode', function () {
@@ -613,7 +614,7 @@ describe('path-to-regexp', function () {
613614
m = re.exec('/route/');
614615

615616
assert.ok(m.length, 1);
616-
assert.equal(m[0], '/route');
617+
assert.equal(m[0], '/route/');
617618
});
618619

619620
it('should match text after an express param', function () {

0 commit comments

Comments
 (0)