path-to-regexp 3.2.0 → 3.3.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.
Files changed (3) hide show
  1. package/index.js +12 -1
  2. package/package.json +1 -1
  3. package/History.md +0 -202
package/index.js CHANGED
@@ -90,6 +90,7 @@ function parse (str, options) {
90
90
  var optional = modifier === '?' || modifier === '*'
91
91
  var pattern = capture || group
92
92
  var delimiter = prev || defaultDelimiter
93
+ var prevText = prev || (typeof tokens[tokens.length - 1] === 'string' ? tokens[tokens.length - 1] : '')
93
94
 
94
95
  tokens.push({
95
96
  name: name || key++,
@@ -99,7 +100,7 @@ function parse (str, options) {
99
100
  repeat: repeat,
100
101
  pattern: pattern
101
102
  ? escapeGroup(pattern)
102
- : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']+?'
103
+ : restrictBacktrack(delimiter, defaultDelimiter, prevText)
103
104
  })
104
105
  }
105
106
 
@@ -111,6 +112,16 @@ function parse (str, options) {
111
112
  return tokens
112
113
  }
113
114
 
115
+ function restrictBacktrack (delimiter, defaultDelimiter, prevText) {
116
+ var charGroup = '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']'
117
+
118
+ if (!prevText || prevText.indexOf(delimiter) > -1 || prevText.indexOf(defaultDelimiter) > -1) {
119
+ return charGroup + '+?'
120
+ }
121
+
122
+ return escapeString(prevText) + '|(?:(?!' + escapeString(prevText) + ')' + charGroup + ')+?'
123
+ }
124
+
114
125
  /**
115
126
  * Compile a string to a template function for the path.
116
127
  *
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": "3.2.0",
4
+ "version": "3.3.0",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
package/History.md DELETED
@@ -1,202 +0,0 @@
1
- 3.0.0 / 2019-01-13
2
- ==================
3
-
4
- * Always use prefix character as delimiter token, allowing any character to be a delimiter (e.g. `/:att1-:att2-:att3-:att4-:att5`)
5
- * Remove `partial` support, prefer escaping the prefix delimiter explicitly (e.g. `\\/(apple-)?icon-:res(\\d+).png`)
6
-
7
- 2.4.0 / 2018-08-26
8
- ==================
9
-
10
- * Support `start` option to disable anchoring from beginning of the string
11
-
12
- 2.3.0 / 2018-08-20
13
- ==================
14
-
15
- * Use `delimiter` when processing repeated matching groups (e.g. `foo/bar` has no prefix, but has a delimiter)
16
-
17
- 2.2.1 / 2018-04-24
18
- ==================
19
-
20
- * Allow empty string with `end: false` to match both relative and absolute paths
21
-
22
- 2.2.0 / 2018-03-06
23
- ==================
24
-
25
- * Pass `token` as second argument to `encode` option (e.g. `encode(value, token)`)
26
-
27
- 2.1.0 / 2017-10-20
28
- ==================
29
-
30
- * Handle non-ending paths where the final character is a delimiter
31
- * E.g. `/foo/` before required either `/foo/` or `/foo//` to match in non-ending mode
32
-
33
- 2.0.0 / 2017-08-23
34
- ==================
35
-
36
- * New option! Ability to set `endsWith` to match paths like `/test?query=string` up to the query string
37
- * New option! Set `delimiters` for specific characters to be treated as parameter prefixes (e.g. `/:test`)
38
- * Remove `isarray` dependency
39
- * Explicitly handle trailing delimiters instead of trimming them (e.g. `/test/` is now treated as `/test/` instead of `/test` when matching)
40
- * Remove overloaded `keys` argument that accepted `options`
41
- * Remove `keys` list attached to the `RegExp` output
42
- * Remove asterisk functionality (it's a real pain to properly encode)
43
- * Change `tokensToFunction` (e.g. `compile`) to accept an `encode` function for pretty encoding (e.g. pass your own implementation)
44
-
45
- 1.7.0 / 2016-11-08
46
- ==================
47
-
48
- * Allow a `delimiter` option to be passed in with `tokensToRegExp` which will be used for "non-ending" token match situations
49
-
50
- 1.6.0 / 2016-10-03
51
- ==================
52
-
53
- * Populate `RegExp.keys` when using the `tokensToRegExp` method (making it consistent with the main export)
54
- * Allow a `delimiter` option to be passed in with `parse`
55
- * Updated TypeScript definition with `Keys` and `Options` updated
56
-
57
- 1.5.3 / 2016-06-15
58
- ==================
59
-
60
- * Add `\\` to the ignore character group to avoid backtracking on mismatched parens
61
-
62
- 1.5.2 / 2016-06-15
63
- ==================
64
-
65
- * Escape `\\` in string segments of regexp
66
-
67
- 1.5.1 / 2016-06-08
68
- ==================
69
-
70
- * Add `index.d.ts` to NPM package
71
-
72
- 1.5.0 / 2016-05-20
73
- ==================
74
-
75
- * Handle partial token segments (better)
76
- * Allow compile to handle asterisk token segments
77
-
78
- 1.4.0 / 2016-05-18
79
- ==================
80
-
81
- * Handle RegExp unions in path matching groups
82
-
83
- 1.3.0 / 2016-05-08
84
- ==================
85
-
86
- * Clarify README language and named parameter token support
87
- * Support advanced Closure Compiler with type annotations
88
- * Add pretty paths options to compiled function output
89
- * Add TypeScript definition to project
90
- * Improved prefix handling with non-complete segment parameters (E.g. `/:foo?-bar`)
91
-
92
- 1.2.1 / 2015-08-17
93
- ==================
94
-
95
- * Encode values before validation with path compilation function
96
- * More examples of using compilation in README
97
-
98
- 1.2.0 / 2015-05-20
99
- ==================
100
-
101
- * Add support for matching an asterisk (`*`) as an unnamed match everything group (`(.*)`)
102
-
103
- 1.1.1 / 2015-05-11
104
- ==================
105
-
106
- * Expose methods for working with path tokens
107
-
108
- 1.1.0 / 2015-05-09
109
- ==================
110
-
111
- * Expose the parser implementation to consumers
112
- * Implement a compiler function to generate valid strings
113
- * Huge refactor of tests to be more DRY and cover new parse and compile functions
114
- * Use chai in tests
115
- * Add .editorconfig
116
-
117
- 1.0.3 / 2015-01-17
118
- ==================
119
-
120
- * Optimised function runtime
121
- * Added `files` to `package.json`
122
-
123
- 1.0.2 / 2014-12-17
124
- ==================
125
-
126
- * Use `Array.isArray` shim
127
- * Remove ES5 incompatible code
128
- * Fixed repository path
129
- * Added new readme badges
130
-
131
- 1.0.1 / 2014-08-27
132
- ==================
133
-
134
- * Ensure installation works correctly on 0.8
135
-
136
- 1.0.0 / 2014-08-17
137
- ==================
138
-
139
- * No more API changes
140
-
141
- 0.2.5 / 2014-08-07
142
- ==================
143
-
144
- * Allow keys parameter to be omitted
145
-
146
- 0.2.4 / 2014-08-02
147
- ==================
148
-
149
- * Code coverage badge
150
- * Updated readme
151
- * Attach keys to the generated regexp
152
-
153
- 0.2.3 / 2014-07-09
154
- ==================
155
-
156
- * Add MIT license
157
-
158
- 0.2.2 / 2014-07-06
159
- ==================
160
-
161
- * A passed in trailing slash in non-strict mode will become optional
162
- * In non-end mode, the optional trailing slash will only match at the end
163
-
164
- 0.2.1 / 2014-06-11
165
- ==================
166
-
167
- * Fixed a major capturing group regexp regression
168
-
169
- 0.2.0 / 2014-06-09
170
- ==================
171
-
172
- * Improved support for arrays
173
- * Improved support for regexps
174
- * Better support for non-ending strict mode matches with a trailing slash
175
- * Travis CI support
176
- * Block using regexp special characters in the path
177
- * Removed support for the asterisk to match all
178
- * New support for parameter suffixes - `*`, `+` and `?`
179
- * Updated readme
180
- * Provide delimiter information with keys array
181
-
182
- 0.1.2 / 2014-03-10
183
- ==================
184
-
185
- * Move testing dependencies to `devDependencies`
186
-
187
- 0.1.1 / 2014-03-10
188
- ==================
189
-
190
- * Match entire substring with `options.end`
191
- * Properly handle ending and non-ending matches
192
-
193
- 0.1.0 / 2014-03-06
194
- ==================
195
-
196
- * Add `options.end`
197
-
198
- 0.0.2 / 2013-02-10
199
- ==================
200
-
201
- * Update to match current express
202
- * Add .license property to component.json