Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fetch scheme restriction in scope keys #190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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