path-to-regexp 1.8.0 → 1.9.0

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.
package/Readme.md CHANGED
@@ -82,7 +82,7 @@ re.exec('/test')
82
82
  //=> ['/test', 'test', undefined]
83
83
 
84
84
  re.exec('/test/route')
85
- //=> ['/test', 'test', 'route']
85
+ //=> ['/test/route', 'test', 'route']
86
86
  ```
87
87
 
88
88
  ##### Zero or more
package/index.js CHANGED
@@ -72,8 +72,9 @@ function parse (str, options) {
72
72
  var partial = prefix != null && next != null && next !== prefix
73
73
  var repeat = modifier === '+' || modifier === '*'
74
74
  var optional = modifier === '?' || modifier === '*'
75
- var delimiter = res[2] || defaultDelimiter
75
+ var delimiter = prefix || defaultDelimiter
76
76
  var pattern = capture || group
77
+ var prevText = prefix || (typeof tokens[tokens.length - 1] === 'string' ? tokens[tokens.length - 1] : '')
77
78
 
78
79
  tokens.push({
79
80
  name: name || key++,
@@ -83,7 +84,7 @@ function parse (str, options) {
83
84
  repeat: repeat,
84
85
  partial: partial,
85
86
  asterisk: !!asterisk,
86
- pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
87
+ pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : restrictBacktrack(delimiter, prevText))
87
88
  })
88
89
  }
89
90
 
@@ -100,6 +101,14 @@ function parse (str, options) {
100
101
  return tokens
101
102
  }
102
103
 
104
+ function restrictBacktrack(delimiter, prevText) {
105
+ if (!prevText || prevText.indexOf(delimiter) > -1) {
106
+ return '[^' + escapeString(delimiter) + ']+?'
107
+ }
108
+
109
+ return escapeString(prevText) + '|(?:(?!' + escapeString(prevText) + ')[^' + escapeString(delimiter) + '])+?'
110
+ }
111
+
103
112
  /**
104
113
  * Compile a string to a template function for the path.
105
114
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "path-to-regexp",
3
3
  "description": "Express style path to RegExp utility",
4
- "version": "1.8.0",
4
+ "version": "1.9.0",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
@@ -11,10 +11,9 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "lint": "standard",
14
- "test-spec": "mocha --require ts-node/register -R spec --bail test.ts",
15
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require ts-node/register -R spec test.ts",
16
- "prepublish": "typings install",
17
- "test": "npm run lint && npm run test-cov"
14
+ "test-spec": "mocha -R spec --bail test.js",
15
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec test.js",
16
+ "test": "npm run test-cov"
18
17
  },
19
18
  "keywords": [
20
19
  "express",
@@ -38,8 +37,7 @@
38
37
  "mocha": "~2.2.4",
39
38
  "standard": "~3.7.3",
40
39
  "ts-node": "^0.5.5",
41
- "typescript": "^1.8.7",
42
- "typings": "^1.0.4"
40
+ "typescript": "^1.8.7"
43
41
  },
44
42
  "dependencies": {
45
43
  "isarray": "0.0.1"
package/History.md DELETED
@@ -1,158 +0,0 @@
1
- 1.7.0 / 2016-11-08
2
- ==================
3
-
4
- * Allow a `delimiter` option to be passed in with `tokensToRegExp` which will be used for "non-ending" token match situations
5
-
6
- 1.6.0 / 2016-10-03
7
- ==================
8
-
9
- * Populate `RegExp.keys` when using the `tokensToRegExp` method (making it consistent with the main export)
10
- * Allow a `delimiter` option to be passed in with `parse`
11
- * Updated TypeScript definition with `Keys` and `Options` updated
12
-
13
- 1.5.3 / 2016-06-15
14
- ==================
15
-
16
- * Add `\\` to the ignore character group to avoid backtracking on mismatched parens
17
-
18
- 1.5.2 / 2016-06-15
19
- ==================
20
-
21
- * Escape `\\` in string segments of regexp
22
-
23
- 1.5.1 / 2016-06-08
24
- ==================
25
-
26
- * Add `index.d.ts` to NPM package
27
-
28
- 1.5.0 / 2016-05-20
29
- ==================
30
-
31
- * Handle partial token segments (better)
32
- * Allow compile to handle asterisk token segments
33
-
34
- 1.4.0 / 2016-05-18
35
- ==================
36
-
37
- * Handle RegExp unions in path matching groups
38
-
39
- 1.3.0 / 2016-05-08
40
- ==================
41
-
42
- * Clarify README language and named parameter token support
43
- * Support advanced Closure Compiler with type annotations
44
- * Add pretty paths options to compiled function output
45
- * Add TypeScript definition to project
46
- * Improved prefix handling with non-complete segment parameters (E.g. `/:foo?-bar`)
47
-
48
- 1.2.1 / 2015-08-17
49
- ==================
50
-
51
- * Encode values before validation with path compilation function
52
- * More examples of using compilation in README
53
-
54
- 1.2.0 / 2015-05-20
55
- ==================
56
-
57
- * Add support for matching an asterisk (`*`) as an unnamed match everything group (`(.*)`)
58
-
59
- 1.1.1 / 2015-05-11
60
- ==================
61
-
62
- * Expose methods for working with path tokens
63
-
64
- 1.1.0 / 2015-05-09
65
- ==================
66
-
67
- * Expose the parser implementation to consumers
68
- * Implement a compiler function to generate valid strings
69
- * Huge refactor of tests to be more DRY and cover new parse and compile functions
70
- * Use chai in tests
71
- * Add .editorconfig
72
-
73
- 1.0.3 / 2015-01-17
74
- ==================
75
-
76
- * Optimised function runtime
77
- * Added `files` to `package.json`
78
-
79
- 1.0.2 / 2014-12-17
80
- ==================
81
-
82
- * Use `Array.isArray` shim
83
- * Remove ES5 incompatible code
84
- * Fixed repository path
85
- * Added new readme badges
86
-
87
- 1.0.1 / 2014-08-27
88
- ==================
89
-
90
- * Ensure installation works correctly on 0.8
91
-
92
- 1.0.0 / 2014-08-17
93
- ==================
94
-
95
- * No more API changes
96
-
97
- 0.2.5 / 2014-08-07
98
- ==================
99
-
100
- * Allow keys parameter to be omitted
101
-
102
- 0.2.4 / 2014-08-02
103
- ==================
104
-
105
- * Code coverage badge
106
- * Updated readme
107
- * Attach keys to the generated regexp
108
-
109
- 0.2.3 / 2014-07-09
110
- ==================
111
-
112
- * Add MIT license
113
-
114
- 0.2.2 / 2014-07-06
115
- ==================
116
-
117
- * A passed in trailing slash in non-strict mode will become optional
118
- * In non-end mode, the optional trailing slash will only match at the end
119
-
120
- 0.2.1 / 2014-06-11
121
- ==================
122
-
123
- * Fixed a major capturing group regexp regression
124
-
125
- 0.2.0 / 2014-06-09
126
- ==================
127
-
128
- * Improved support for arrays
129
- * Improved support for regexps
130
- * Better support for non-ending strict mode matches with a trailing slash
131
- * Travis CI support
132
- * Block using regexp special characters in the path
133
- * Removed support for the asterisk to match all
134
- * New support for parameter suffixes - `*`, `+` and `?`
135
- * Updated readme
136
- * Provide delimiter information with keys array
137
-
138
- 0.1.2 / 2014-03-10
139
- ==================
140
-
141
- * Move testing dependencies to `devDependencies`
142
-
143
- 0.1.1 / 2014-03-10
144
- ==================
145
-
146
- * Match entire substring with `options.end`
147
- * Properly handle ending and non-ending matches
148
-
149
- 0.1.0 / 2014-03-06
150
- ==================
151
-
152
- * Add `options.end`
153
-
154
- 0.0.2 / 2013-02-10
155
- ==================
156
-
157
- * Update to match current express
158
- * Add .license property to component.json