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
This commit is contained in:
George Kalpakas 2018-04-12 23:34:43 +03:00 committed by Igor Minar
parent 08325aaffc
commit 6c2c95851a
3 changed files with 12 additions and 5 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
const WILD_SINGLE = '[^\\/]+';
const WILD_SINGLE = '[^\\/]*';
const WILD_OPEN = '(?:.+\\/)?';
const TO_ESCAPE = [

View File

@ -81,7 +81,7 @@ import {MockFilesystem} from '../testing/mock';
patterns: [
'\\/absolute\\/.*',
'\\/some\\/url\\?with\\+escaped\\+chars',
'\\/test\\/relative\\/[^\\/]+\\.txt',
'\\/test\\/relative\\/[^\\/]*\\.txt',
]
}],
dataGroups: [{
@ -97,7 +97,7 @@ import {MockFilesystem} from '../testing/mock';
{positive: true, regex: '^\\/included\\/absolute\\/.*$'},
{positive: false, regex: '^\\/excluded\\/absolute\\/.*$'},
{positive: true, regex: '^\\/included\\/some\\/url\\?with\\+escaped\\+chars$'},
{positive: false, regex: '^\\/test\\/excluded\\/relative\\/[^\\/]+\\.txt$'},
{positive: false, regex: '^\\/test\\/excluded\\/relative\\/[^\\/]*\\.txt$'},
{positive: true, regex: '^http:\\/\\/example\\.com\\/included$'},
{positive: false, regex: '^http:\\/\\/example\\.com\\/excluded$'},
],
@ -129,8 +129,9 @@ import {MockFilesystem} from '../testing/mock';
dataGroups: [],
navigationUrls: [
{positive: true, regex: '^\\/.*$'},
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]+\\.[^\\/]+$'},
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]+__[^\\/]+\\/.*$'},
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]*\\.[^\\/]*$'},
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]*__[^\\/]*$'},
{positive: false, regex: '^\\/(?:.+\\/)?[^\\/]*__[^\\/]*\\/.*$'},
],
hashTable: {}
});

View File

@ -688,6 +688,12 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
expect(await navRequest('/baz/x__x/qux')).toBeNull();
server.assertSawRequestFor('/baz/x__x/qux');
expect(await navRequest('/baz/__')).toBeNull();
server.assertSawRequestFor('/baz/__');
expect(await navRequest('/baz/__/qux')).toBeNull();
server.assertSawRequestFor('/baz/__/qux');
});
describe('(with custom `navigationUrls`)', () => {