feat(service-worker): add support for ?
in SW config globbing (#24105)
The globbing is used in the following sections: - `assetGroups` > `resources` > `files`/`versionedFiles` - `assetGroups` > `resources` > `urls` - `dataGroups` > `urls` - `navigationUrls` Query params are ignored for `files`/`versionedFiles` and `navigationUrls`, but they are still taken into account for `assetGroups`/`dataGroups` `urls`. To avoid a breaking change, `?` is matched literally for these patterns. PR Close #24105
This commit is contained in:

committed by
Miško Hevery

parent
94076c934c
commit
250527ca68
@ -6,17 +6,26 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
const WILD_SINGLE = '[^\\/]*';
|
||||
const QUESTION_MARK = '[^/]';
|
||||
const WILD_SINGLE = '[^/]*';
|
||||
const WILD_OPEN = '(?:.+\\/)?';
|
||||
|
||||
const TO_ESCAPE = [
|
||||
const TO_ESCAPE_BASE = [
|
||||
{replace: /\./g, with: '\\.'},
|
||||
{replace: /\?/g, with: '\\?'},
|
||||
{replace: /\+/g, with: '\\+'},
|
||||
{replace: /\*/g, with: WILD_SINGLE},
|
||||
];
|
||||
const TO_ESCAPE_WILDCARD_QM = [
|
||||
...TO_ESCAPE_BASE,
|
||||
{replace: /\?/g, with: QUESTION_MARK},
|
||||
];
|
||||
const TO_ESCAPE_LITERAL_QM = [
|
||||
...TO_ESCAPE_BASE,
|
||||
{replace: /\?/g, with: '\\?'},
|
||||
];
|
||||
|
||||
export function globToRegex(glob: string): string {
|
||||
export function globToRegex(glob: string, literalQuestionMark = false): string {
|
||||
const toEscape = literalQuestionMark ? TO_ESCAPE_LITERAL_QM : TO_ESCAPE_WILDCARD_QM;
|
||||
const segments = glob.split('/').reverse();
|
||||
let regex: string = '';
|
||||
while (segments.length > 0) {
|
||||
@ -28,7 +37,7 @@ export function globToRegex(glob: string): string {
|
||||
regex += '.*';
|
||||
}
|
||||
} else {
|
||||
const processed = TO_ESCAPE.reduce(
|
||||
const processed = toEscape.reduce(
|
||||
(segment, escape) => segment.replace(escape.replace, escape.with), segment);
|
||||
regex += processed;
|
||||
if (segments.length > 0) {
|
||||
|
Reference in New Issue
Block a user