Skip to content

Commit 6c2c958

Browse files
gkalpakIgorMinar
authored andcommitted
fix(service-worker): let * match 0 characters in globs (#23339)
In [glob patterns][1], the `*` wildcard is supposed to match 0 or more characters. For reference: - This is also how `*` works in other implementations, such as `.gitignore` files or Firebase hosting config. - Some popular JS implementations (e.g. [minimatch][2], [micromatch][3]) work differently, matching 1 or more character (but not 0). This commit "fixes" the minimal glob support in `@angular/service-worker` to allow `*` to also match 0 characters. [1]: https://en.wikipedia.org/wiki/Glob_%28programming%29 [2]: https://www.npmjs.com/package/minimatch [3]: https://www.npmjs.com/package/micromatch PR Close #23339
1 parent 08325aa commit 6c2c958

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/service-worker/config/src/glob.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
const WILD_SINGLE = '[^\\/]+';
9+
const WILD_SINGLE = '[^\\/]*';
1010
const WILD_OPEN = '(?:.+\\/)?';
1111

1212
const TO_ESCAPE = [

packages/service-worker/config/test/generator_spec.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import {MockFilesystem} from '../testing/mock';
8181
patterns: [
8282
'\\/absolute\\/.*',
8383
'\\/some\\/url\\?with\\+escaped\\+chars',
84-
'\\/test\\/relative\\/[^\\/]+\\.txt',
84+
'\\/test\\/relative\\/[^\\/]*\\.txt',
8585
]
8686
}],
8787
dataGroups: [{
@@ -97,7 +97,7 @@ import {MockFilesystem} from '../testing/mock';
9797
{positive: true, regex: '^\\/included\\/absolute\\/.*$'},
9898
{positive: false, regex: '^\\/excluded\\/absolute\\/.*$'},
9999
{positive: true, regex: '^\\/included\\/some\\/url\\?with\\+escaped\\+chars$'},
100-
{positive: false, regex: '^\\/test\\/excluded\\/relative\\/[^\\/]+\\.txt$'},
100+
{positive: false, regex: '^\\/test\\/excluded\\/relative\\/[^\\/]*\\.txt$'},
101101
{positive: true, regex: '^http:\\/\\/example\\.com\\/included$'},
102102
{positive: false, regex: '^http:\\/\\/example\\.com\\/excluded$'},
103103
],
@@ -129,8 +129,9 @@ import {MockFilesystem} from '../testing/mock';
129129
dataGroups: [],
130130
navigationUrls: [
131131
{positive: true, regex: '^\\/.*$'},
132-
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]+\\.[^\\/]+$'},
133-
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]+__[^\\/]+\\/.*$'},
132+
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]*\\.[^\\/]*$'},
133+
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]*__[^\\/]*$'},
134+
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]*__[^\\/]*\\/.*$'},
134135
],
135136
hashTable: {}
136137
});

packages/service-worker/worker/test/happy_spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,12 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
688688

689689
expect(await navRequest('/baz/x__x/qux')).toBeNull();
690690
server.assertSawRequestFor('/baz/x__x/qux');
691+
692+
expect(await navRequest('/baz/__')).toBeNull();
693+
server.assertSawRequestFor('/baz/__');
694+
695+
expect(await navRequest('/baz/__/qux')).toBeNull();
696+
server.assertSawRequestFor('/baz/__/qux');
691697
});
692698

693699
describe('(with custom `navigationUrls`)', () => {

0 commit comments

Comments
 (0)