Skip to content

Commit

Permalink
Remove fetch scheme restriction in scope keys
Browse files Browse the repository at this point in the history
Fixes #188.
  • Loading branch information
hiroshige-g authored and domenic committed Oct 16, 2019
1 parent 2333e56 commit 8f81211
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
15 changes: 7 additions & 8 deletions reference-implementation/__tests__/parsing-scope-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Relative URL scope keys', () => {
});

describe('Absolute URL scope keys', () => {
it('should only accept absolute URL scope keys with fetch schemes', () => {
it('should accept all absolute URL scope keys, with or without fetch schemes', () => {
expectScopes(
[
'about:good',
Expand All @@ -87,14 +87,13 @@ describe('Absolute URL scope keys', () => {
'filesystem:http://example.com/good/',
'http://good/',
'https://good/',
'ftp://good/'
'ftp://good/',
'import:bad',
'mailto:bad',
'javascript:bad',
'wss://ba/'
],
[
'Invalid scope "import:bad". Scope URLs must have a fetch scheme.',
'Invalid scope "mailto:bad". Scope URLs must have a fetch scheme.',
'Invalid scope "javascript:bad". Scope URLs must have a fetch scheme.',
'Invalid scope "wss://ba/". Scope URLs must have a fetch scheme.'
]
[]
);
});

Expand Down
7 changes: 1 addition & 6 deletions reference-implementation/lib/parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const assert = require('assert');
const { tryURLParse, hasFetchScheme, tryURLLikeSpecifierParse } = require('./utils.js');
const { tryURLParse, tryURLLikeSpecifierParse } = require('./utils.js');

exports.parseFromString = (input, baseURL) => {
const parsed = JSON.parse(input);
Expand Down Expand Up @@ -92,11 +92,6 @@ function sortAndNormalizeScopes(obj, baseURL) {
continue;
}

if (!hasFetchScheme(scopePrefixURL)) {
console.warn(`Invalid scope "${scopePrefixURL}". Scope URLs must have a fetch scheme.`);
continue;
}

const normalizedScopePrefix = scopePrefixURL.href;
normalized[normalizedScopePrefix] = sortAndNormalizeSpecifierMap(potentialSpecifierMap, baseURL);
}
Expand Down
7 changes: 0 additions & 7 deletions reference-implementation/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';
const { URL } = require('url');

// https://fetch.spec.whatwg.org/#fetch-scheme
const FETCH_SCHEMES = new Set(['http', 'https', 'ftp', 'about', 'blob', 'data', 'file', 'filesystem']);

exports.tryURLParse = (string, baseURL) => {
try {
return new URL(string, baseURL);
Expand All @@ -20,7 +17,3 @@ exports.tryURLLikeSpecifierParse = (specifier, baseURL) => {
const url = exports.tryURLParse(specifier);
return url;
};

exports.hasFetchScheme = url => {
return FETCH_SCHEMES.has(url.protocol.slice(0, -1));
};
3 changes: 0 additions & 3 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ To <dfn>register an import map</dfn> given an {{HTMLScriptElement}} |element|:
1. If |scopePrefixURL| is failure, then:
1. [=Report a warning to the console=] that the scope prefix URL was not parseable.
1. [=Continue=].
1. If |scopePrefixURL|'s [=url/scheme=] is not a [=fetch scheme=], then:
1. [=Report a warning to the console=] that scope prefix URLs must have a fetch scheme.
1. [=Continue=].
1. Let |normalizedScopePrefix| be the [=URL serializer|serialization=] of |scopePrefixURL|.
1. Set |normalized|[|normalizedScopePrefix|] to the result of [=sorting and normalizing a specifier map=] given |potentialSpecifierMap| and |baseURL|.
1. Return the result of [=map/sorting=] |normalized|, with an entry |a| being less than an entry |b| if |b|'s [=map/key=] is [=code unit less than=] |a|'s [=map/key=].
Expand Down

0 comments on commit 8f81211

Please sign in to comment.