Skip to content

Commit

Permalink
switch maps from URLs to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Aug 8, 2019
1 parent 3631bc6 commit c82b348
Show file tree
Hide file tree
Showing 15 changed files with 413 additions and 351 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/reference-implementation/node_modules/
/reference-implementation/coverage/
/out/
/spec.html
/deploy_key
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_js:
before_install:
- cd reference-implementation
script:
- npm run lint
- npm test
- cd .. && bash ./deploy.sh

Expand Down
22 changes: 22 additions & 0 deletions reference-implementation/__tests__/composition.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,27 @@ describe('Composition', () => {
}
});
});

it('should produce maps with scopes in sorted order', () => {
expect(Object.keys(composeMaps([
{
imports: {},
scopes: {
'https://example.com/x/': { 'https://c/': 'https://f/' }
}
},
{
imports: {},
scopes: {
'https://example.com/x/y/': { 'https://a/': 'https://b/' },
'https://example.com/x/y/z': { 'https://c/': 'https://d/' }
}
}
]).scopes)).toStrictEqual([
'https://example.com/x/y/z',
'https://example.com/x/y/',
'https://example.com/x/'
]);
});
});

176 changes: 75 additions & 101 deletions reference-implementation/__tests__/parsing-addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('Relative URL-like addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
dotSlash: [expect.toMatchURL('https://base.example/path1/path2/foo')],
dotDotSlash: [expect.toMatchURL('https://base.example/path1/foo')],
slash: [expect.toMatchURL('https://base.example/foo')]
dotSlash: ['https://base.example/path1/path2/foo'],
dotDotSlash: ['https://base.example/path1/foo'],
slash: ['https://base.example/foo']
}
);
});
Expand All @@ -33,9 +33,9 @@ describe('Relative URL-like addresses', () => {
slash: []
},
[
`Invalid address "./foo" for the specifier key "dotSlash".`,
`Invalid address "../foo" for the specifier key "dotDotSlash".`,
`Invalid address "/foo" for the specifier key "slash".`
`Path-based module specifier "./foo" cannot be used with a base URL that uses the "data:" scheme.`,
`Path-based module specifier "../foo" cannot be used with a base URL that uses the "data:" scheme.`,
`Path-based module specifier "/foo" cannot be used with a base URL that uses the "data:" scheme.`
]
);
});
Expand All @@ -49,14 +49,14 @@ describe('Relative URL-like addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
dotSlash: [expect.toMatchURL('https://base.example/path1/path2/')],
dotDotSlash: [expect.toMatchURL('https://base.example/path1/')],
slash: [expect.toMatchURL('https://base.example/')]
dotSlash: ['https://base.example/path1/path2/'],
dotDotSlash: ['https://base.example/path1/'],
slash: ['https://base.example/']
}
);
});

it('should ignore percent-encoded variants of ./, ../, or /', () => {
it('should treat percent-encoded variants of ./, ../, or / as non-URLs', () => {
expectSpecifierMap(
`{
"dotSlash1": "%2E/",
Expand All @@ -69,23 +69,15 @@ describe('Relative URL-like addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
dotSlash1: [],
dotDotSlash1: [],
dotSlash2: [],
dotDotSlash2: [],
slash2: [],
dotSlash3: [],
dotDotSlash3: []
dotSlash1: ['%2E/'],
dotDotSlash1: ['%2E%2E/'],
dotSlash2: ['.%2F'],
dotDotSlash2: ['..%2F'],
slash2: ['%2F'],
dotSlash3: ['%2E%2F'],
dotDotSlash3: ['%2E%2E%2F']
},
[
`Invalid address "%2E/" for the specifier key "dotSlash1".`,
`Invalid address "%2E%2E/" for the specifier key "dotDotSlash1".`,
`Invalid address ".%2F" for the specifier key "dotSlash2".`,
`Invalid address "..%2F" for the specifier key "dotDotSlash2".`,
`Invalid address "%2F" for the specifier key "slash2".`,
`Invalid address "%2E%2F" for the specifier key "dotSlash3".`,
`Invalid address "%2E%2E%2F" for the specifier key "dotDotSlash3".`
]
[]
);
});
});
Expand All @@ -98,21 +90,21 @@ describe('Built-in module addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
foo: [expect.toMatchURL(`${BUILT_IN_MODULE_SCHEME}:foo`)]
foo: [`${BUILT_IN_MODULE_SCHEME}:foo`]
}
);
});

it('should ignore percent-encoded variants of the built-in module scheme', () => {
it('should treat percent-encoded variants of the built-in module scheme as non-URLs', () => {
expectSpecifierMap(
`{
"foo": "${encodeURIComponent(BUILT_IN_MODULE_SCHEME + ':')}foo"
}`,
'https://base.example/path1/path2/path3',
{
foo: []
foo: [`${encodeURIComponent(BUILT_IN_MODULE_SCHEME + ':')}foo`]
},
[`Invalid address "${encodeURIComponent(BUILT_IN_MODULE_SCHEME + ':')}foo" for the specifier key "foo".`]
[]
);
});

Expand All @@ -125,9 +117,9 @@ describe('Built-in module addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
slashEnd: [expect.toMatchURL(`${BUILT_IN_MODULE_SCHEME}:foo/`)],
slashMiddle: [expect.toMatchURL(`${BUILT_IN_MODULE_SCHEME}:foo/bar`)],
backslash: [expect.toMatchURL(`${BUILT_IN_MODULE_SCHEME}:foo\\baz`)]
slashEnd: [`${BUILT_IN_MODULE_SCHEME}:foo/`],
slashMiddle: [`${BUILT_IN_MODULE_SCHEME}:foo/bar`],
backslash: [`${BUILT_IN_MODULE_SCHEME}:foo\\baz`]
}
);
});
Expand All @@ -152,25 +144,20 @@ describe('Absolute URL addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
about: [expect.toMatchURL('about:good')],
blob: [expect.toMatchURL('blob:good')],
data: [expect.toMatchURL('data:good')],
file: [expect.toMatchURL('file:///good')],
filesystem: [expect.toMatchURL('filesystem:good')],
http: [expect.toMatchURL('http://good/')],
https: [expect.toMatchURL('https://good/')],
ftp: [expect.toMatchURL('ftp://good/')],
import: [],
mailto: [],
javascript: [],
wss: []
about: ['about:good'],
blob: ['blob:good'],
data: ['data:good'],
file: ['file:///good'],
filesystem: ['filesystem:good'],
http: ['http://good/'],
https: ['https://good/'],
ftp: ['ftp://good/'],
import: ['import:bad'],
mailto: ['mailto:bad'],
javascript: ['javascript:bad'],
wss: ['wss:bad']
},
[
`Invalid address "import:bad" for the specifier key "import".`,
`Invalid address "mailto:bad" for the specifier key "mailto".`,
`Invalid address "javascript:bad" for the specifier key "javascript".`,
`Invalid address "wss:bad" for the specifier key "wss".`
]
[]
);
});

Expand All @@ -192,29 +179,24 @@ describe('Absolute URL addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
about: [expect.toMatchURL('about:good')],
blob: [expect.toMatchURL('blob:good')],
data: [expect.toMatchURL('data:good')],
file: [expect.toMatchURL('file:///good')],
filesystem: [expect.toMatchURL('filesystem:good')],
http: [expect.toMatchURL('http://good/')],
https: [expect.toMatchURL('https://good/')],
ftp: [expect.toMatchURL('ftp://good/')],
import: [],
mailto: [],
javascript: [],
wss: []
about: ['about:good'],
blob: ['blob:good'],
data: ['data:good'],
file: ['file:///good'],
filesystem: ['filesystem:good'],
http: ['http://good/'],
https: ['https://good/'],
ftp: ['ftp://good/'],
import: ['import:bad'],
mailto: ['mailto:bad'],
javascript: ['javascript:bad'],
wss: ['wss:bad']
},
[
`Invalid address "import:bad" for the specifier key "import".`,
`Invalid address "mailto:bad" for the specifier key "mailto".`,
`Invalid address "javascript:bad" for the specifier key "javascript".`,
`Invalid address "wss:bad" for the specifier key "wss".`
]
[]
);
});

it('should parse absolute URLs, ignoring unparseable ones', () => {
it('should parse/normalize absolute URLs, and treat unparseable ones as non-URLs', () => {
expectSpecifierMap(
`{
"unparseable1": "https://ex ample.org/",
Expand All @@ -228,20 +210,16 @@ describe('Absolute URL addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
unparseable1: [],
unparseable2: [],
unparseable3: [],
invalidButParseable1: [expect.toMatchURL('https://example.org/')],
invalidButParseable2: [expect.toMatchURL('https://example.com///')],
prettyNormal: [expect.toMatchURL('https://example.net/')],
percentDecoding: [expect.toMatchURL('https://example.com/')],
noPercentDecoding: [expect.toMatchURL('https://example.com/%41')]
unparseable1: ['https://ex ample.org/'],
unparseable2: ['https://example.com:demo'],
unparseable3: ['http://[www.example.com]/'],
invalidButParseable1: ['https://example.org/'],
invalidButParseable2: ['https://example.com///'],
prettyNormal: ['https://example.net/'],
percentDecoding: ['https://example.com/'],
noPercentDecoding: ['https://example.com/%41']
},
[
`Invalid address "https://ex ample.org/" for the specifier key "unparseable1".`,
`Invalid address "https://example.com:demo" for the specifier key "unparseable2".`,
`Invalid address "http://[www.example.com]/" for the specifier key "unparseable3".`
]
[]
);
});

Expand All @@ -259,20 +237,16 @@ describe('Absolute URL addresses', () => {
}`,
'https://base.example/path1/path2/path3',
{
unparseable1: [],
unparseable2: [],
unparseable3: [],
invalidButParseable1: [expect.toMatchURL('https://example.org/')],
invalidButParseable2: [expect.toMatchURL('https://example.com///')],
prettyNormal: [expect.toMatchURL('https://example.net/')],
percentDecoding: [expect.toMatchURL('https://example.com/')],
noPercentDecoding: [expect.toMatchURL('https://example.com/%41')]
unparseable1: ['https://ex ample.org/'],
unparseable2: ['https://example.com:demo'],
unparseable3: ['http://[www.example.com]/'],
invalidButParseable1: ['https://example.org/'],
invalidButParseable2: ['https://example.com///'],
prettyNormal: ['https://example.net/'],
percentDecoding: ['https://example.com/'],
noPercentDecoding: ['https://example.com/%41']
},
[
`Invalid address "https://ex ample.org/" for the specifier key "unparseable1".`,
`Invalid address "https://example.com:demo" for the specifier key "unparseable2".`,
`Invalid address "http://[www.example.com]/" for the specifier key "unparseable3".`
]
[]
);
});
});
Expand Down Expand Up @@ -322,8 +296,8 @@ describe('Failing addresses: mismatched trailing slashes', () => {
}`,
'https://base.example/path1/path2/path3',
{
'trailer/': [expect.toMatchURL('https://base.example/atrailer/')],
[`${BUILT_IN_MODULE_SCHEME}:trailer/`]: [expect.toMatchURL('https://base.example/bim-atrailer/')]
'trailer/': ['https://base.example/atrailer/'],
[`${BUILT_IN_MODULE_SCHEME}:trailer/`]: ['https://base.example/bim-atrailer/']
},
[
`Invalid address "https://base.example/notrailer" for package specifier key "trailer/". Package addresses must end with "/".`,
Expand All @@ -334,17 +308,17 @@ describe('Failing addresses: mismatched trailing slashes', () => {
});

describe('Other invalid addresses', () => {
it('should ignore unprefixed strings that are not absolute URLs', () => {
it('should treat unprefixed strings that are not absolute URLs as non-URLs', () => {
for (const bad of ['bar', '\\bar', '~bar', '#bar', '?bar']) {
expectSpecifierMap(
`{
"foo": ${JSON.stringify(bad)}
}`,
'https://base.example/path1/path2/path3',
{
foo: []
foo: [bad]
},
[`Invalid address "${bad}" for the specifier key "foo".`]
[]
);
}
});
Expand Down
12 changes: 6 additions & 6 deletions reference-implementation/__tests__/parsing-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Mismatching the specifier map schema', () => {
}`,
'https://base.example/',
{
bar: [expect.toMatchURL('https://example.com/')]
bar: ['https://example.com/']
},
[
`Invalid address ${invalid} for the specifier key "foo". ` +
Expand All @@ -74,7 +74,7 @@ describe('Mismatching the specifier map schema', () => {
}`,
'https://base.example/',
{},
[`Invalid empty string specifier key.`]
[`Invalid empty string specifier.`]
);
});

Expand All @@ -87,8 +87,8 @@ describe('Mismatching the specifier map schema', () => {
}`,
'https://base.example/',
{
foo: [expect.toMatchURL('https://example.com/')],
bar: [expect.toMatchURL('https://example.com/')]
foo: ['https://example.com/'],
bar: ['https://example.com/']
},
[
`Invalid address ${invalid} inside the address array for the specifier key "foo". ` +
Expand Down Expand Up @@ -130,8 +130,8 @@ describe('Normalization', () => {
}`,
'https://base.example/',
{
foo: [expect.toMatchURL('https://example.com/1')],
bar: [expect.toMatchURL('https://example.com/2')],
foo: ['https://example.com/1'],
bar: ['https://example.com/2'],
baz: []
}
);
Expand Down
Loading

0 comments on commit c82b348

Please sign in to comment.