path-to-regexp 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of path-to-regexp might be problematic. Click here for more details.
- package/Readme.md +1 -1
- package/index.js +15 -3
- package/package.json +1 -1
- package/History.md +0 -26
package/Readme.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Turn an Express-style path string such as `/user/:name` into a regular expression.
|
4
4
|
|
5
|
-
**Note:** This is a legacy branch. You should upgrade to `1.x`.
|
5
|
+
**Note:** This is a legacy branch. You should upgrade to `1.x`.
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
package/index.js
CHANGED
@@ -7,7 +7,7 @@ module.exports = pathtoRegexp;
|
|
7
7
|
/**
|
8
8
|
* Match matching groups in a regular expression.
|
9
9
|
*/
|
10
|
-
var MATCHING_GROUP_REGEXP = /\((?!\?)/g;
|
10
|
+
var MATCHING_GROUP_REGEXP = /\((?:\?<(.*?)>)?(?!\?)/g;
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Normalize the given path string,
|
@@ -40,7 +40,7 @@ function pathtoRegexp(path, keys, options) {
|
|
40
40
|
if (path instanceof RegExp) {
|
41
41
|
while (m = MATCHING_GROUP_REGEXP.exec(path.source)) {
|
42
42
|
keys.push({
|
43
|
-
name: name++,
|
43
|
+
name: m[1] || name++,
|
44
44
|
optional: false,
|
45
45
|
offset: m.index
|
46
46
|
});
|
@@ -91,7 +91,7 @@ function pathtoRegexp(path, keys, options) {
|
|
91
91
|
var len = keys.length
|
92
92
|
|
93
93
|
while (len-- > keysOffset && keys[len].offset > index) {
|
94
|
-
keys[len].offset += 3;
|
94
|
+
keys[len].offset += 3; // Replacement length minus asterisk length.
|
95
95
|
}
|
96
96
|
|
97
97
|
return '(.*)';
|
@@ -99,6 +99,18 @@ function pathtoRegexp(path, keys, options) {
|
|
99
99
|
|
100
100
|
// This is a workaround for handling unnamed matching groups.
|
101
101
|
while (m = MATCHING_GROUP_REGEXP.exec(path)) {
|
102
|
+
var escapeCount = 0;
|
103
|
+
var index = m.index;
|
104
|
+
|
105
|
+
while (path.charAt(--index) === '\\') {
|
106
|
+
escapeCount++;
|
107
|
+
}
|
108
|
+
|
109
|
+
// It's possible to escape the bracket.
|
110
|
+
if (escapeCount % 2 === 1) {
|
111
|
+
continue;
|
112
|
+
}
|
113
|
+
|
102
114
|
if (keysOffset + i === keys.length || keys[keysOffset + i].offset > m.index) {
|
103
115
|
keys.splice(keysOffset + i, 0, {
|
104
116
|
name: name++, // Unnamed matching groups must be consistently linear.
|
package/package.json
CHANGED
package/History.md
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
0.1.5 / 2015-05-08
|
2
|
-
==================
|
3
|
-
|
4
|
-
* Add an index property for position in match result.
|
5
|
-
|
6
|
-
0.1.4 / 2015-03-05
|
7
|
-
==================
|
8
|
-
|
9
|
-
* Add license information
|
10
|
-
|
11
|
-
0.1.3 / 2014-07-06
|
12
|
-
==================
|
13
|
-
|
14
|
-
* Better array support
|
15
|
-
* Improved support for trailing slash in non-ending mode
|
16
|
-
|
17
|
-
0.1.0 / 2014-03-06
|
18
|
-
==================
|
19
|
-
|
20
|
-
* add options.end
|
21
|
-
|
22
|
-
0.0.2 / 2013-02-10
|
23
|
-
==================
|
24
|
-
|
25
|
-
* Update to match current express
|
26
|
-
* add .license property to component.json
|