-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2: Warn on usage of Express-style wildcard characters #1049
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
/* eslint-env browser, serviceworker */ | ||
|
||
import logHelper from '../../../../lib/log-helper'; | ||
import { | ||
Router as SWRoutingRouter, | ||
ExpressRoute, | ||
|
@@ -101,6 +102,26 @@ class Router extends SWRoutingRouter { | |
if (capture.length === 0) { | ||
throw ErrorFactory.createError('empty-express-string'); | ||
} | ||
// See https://github.com/pillarjs/path-to-regexp#parameters | ||
const wildcards = '[*:?+]'; | ||
const valueToCheck = capture.startsWith('http') ? | ||
new URL(capture, location).pathname : | ||
capture; | ||
const match = valueToCheck.match(new RegExp(`${wildcards}`)); | ||
if (match) { | ||
logHelper.warn({ | ||
message: `registerRoute() was called with a string containing an ` + | ||
`Express-style wildcard character. While this is currently ` + | ||
`supported, it will no longer be treated as a wildcard match in ` + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify the message here. Suggestion: |
||
`an upcoming release of Workbox. For equivalent behavior, please ` + | ||
`switch to using a regular expression instead.`, | ||
data: { | ||
'Path String': capture, | ||
'Wildcard Character': match[0], | ||
'Learn More': 'https://goo.gl/xZMKEV', | ||
}, | ||
}); | ||
} | ||
route = new ExpressRoute({path: capture, handler, method}); | ||
} else if (capture instanceof RegExp) { | ||
route = new RegExpRoute({regExp: capture, handler, method}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Change
match
topossibleExpressString