Releases: pillarjs/path-to-regexp
Releases · pillarjs/path-to-regexp
Strict mode
Added
- Adds a
strict
option to detect potential ReDOS issues
Fixed
- Fixes separator to default to
suffix + prefix
when not specified - Allows separator to be undefined in
TokenData
- This is only relevant if you are building
TokenData
manually, previouslyparse
filled it in automatically
- This is only relevant if you are building
Comments
- I highly recommend enabling
strict: true
and I'm probably releasing a V8 with it enabled by default ASAP as a necessary security mitigation
Wildcard, unicode, and modifier changes
Hi all! There's a few major breaking changes in this release so read carefully.
Breaking changes:
- The function returned by
compile
only accepts strings as values (i.e. no numbers, useString(value)
before compiling a path)- For repeated values, when
encode !== false
, it must be an array of strings
- For repeated values, when
- Parameter names can contain all unicode identifier characters (defined as regex
\p{XID_Continue}
). - Modifiers (
?
,*
,+
) must be used after a param explicitly wrapped in{}
- No more implied prefix of
/
or.
- No more implied prefix of
- No support for arrays or regexes as inputs
- The wildcard (standalone
*
) has been added back and matches Express.js expected behavior - Removed
endsWith
option - Renamed
strict: true
totrailing: false
- Reserved
;
,,
,!
, and@
for future use-cases - Removed
tokensToRegexp
,tokensToFunction
andregexpToFunction
in favor of simplifying exports - Enable a "loose" mode by default, so
/
can be repeated multiple times in a matched path (i.e./foo
works like//foo
, etc) encode
anddecode
no longer receive the token as the second parameter- Removed the ESM + CommonJS dual package in favor of only one CommonJS supported export
- Minimum JS support for ES2020 (previous ES2015)
- Encode defaults to
encodeURIComponent
and decode defaults todecodeURIComponent
Added:
- Adds
encodePath
to fix an issue aroundencode
being used for both path and parameters (the path and parameter should be encoded slightly differently) - Adds
loose
as an option to support arbitrarily matching the delimiter in paths, e.g.foo/bar
andfoo///bar
should work the same - Allow
encode
anddecode
to be set tofalse
which skips all processing of the parameters input/output - All remaining methods support
TokenData
(exported, returned byparse
) as input- This should be useful if you are programmatically building paths to match or want to avoid parsing multiple times
Requests for feedback:
- Requiring
{}
is an obvious drawback but I'm seeking feedback on whether it helps make path behavior clearer- Related: Removing
/
and.
as implicit prefixes
- Related: Removing
- Removing array and regex support is to reduce the overall package size for things many users don't need
- Unicode IDs are added to align more closely with browser URLPattern behavior, which uses JS identifiers
Updated README
No API changes. Documentation only release.
Changed
Support named matching groups in `RegExp`
Fix matching `:name*` parameter
Named Capturing Groups
Use `/#?` as Default Delimiter
Fixed
- Use
/#?
as default delimiter to avoid matching on query or fragment parameters- If you are matching non-paths (e.g. hostnames), you can adjust
delimiter: '.'
- If you are matching non-paths (e.g. hostnames), you can adjust
Custom Prefix and Suffix Groups
This release reverts the prefix behavior added in v3 back to the behavior seen in v2. For the most part, path matching is backward compatible with v2 with these enhancements:
- Support for nested non-capturing groups in regexp, e.g.
/(abc(?=d))
- Support for custom prefix and suffix groups using
/{abc(.*)def}
- Tokens in an unexpected position will throw an error
- Paths like
/test(foo
previously worked treating(
as a literal character, now it expects(
to be closed and is treated as a group - You can escape the character for the previous behavior, e.g.
/test\(foo
- Paths like
Changed
- Revert using any character as prefix, support
prefixes
option to configure this (starts as/.
which acts like every version since 0.x again) - Add support for
{}
to capture prefix/suffix explicitly, enables custom use-cases like/:attr1{-:attr2}?
Remove Default Encode URI Component
No changes to path rules since 3.x, except support for nested RegEx parts in 4.x.
Changed
- Rename
RegexpOptions
interface toTokensToRegexpOptions
- Remove
normalizePathname
from library, document solution in README - Encode using identity function as default, not
encodeURIComponent
Decode URI
Removed
- Remove
whitelist
in favor ofdecodeURI
(advanced behavior can happen outsidepath-to-regexp
)