From f5ca4f224ec24bbad2839a849e79d280d90355cb Mon Sep 17 00:00:00 2001 From: Hiroshige Hayashizaki Date: Wed, 12 Feb 2020 17:56:27 -0800 Subject: [PATCH] [Import Maps] Make errors block the whole resolution, Blink-side Reflects https://github.com/WICG/import-maps/pull/205. This CL updates tests from #205. To match the behavior with the updated spec, this CL turns non-String values into `null` entries (i.e. make whole resolution fail without further fallback), instead of ignoring such entries. Other aspects were already conformant with the updated spec (i.e. weren't matching with the spec before #205). This CL updates (test-only) import maps serialization code so that it matches with the reference implementation, i.e. dump `null` entries as `null` instead of `[]`. This CL also updates spec comments. Bug: 990561, https://github.com/WICG/import-maps/issues/184 Change-Id: Ifa2d04bf20fcef5575c14d135c328730ea09c454 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037012 Commit-Queue: Hiroshige Hayashizaki Reviewed-by: Kouhei Ueno Cr-Commit-Position: refs/heads/master@{#740847} --- import-maps/common/resolving.tentative.html | 1 + .../resources/parsing-addresses-absolute.json | 2 + .../resources/parsing-addresses-invalid.json | 8 +- .../common/resources/parsing-addresses.json | 16 +++- .../parsing-schema-specifier-map.json | 6 ++ .../resources/parsing-trailing-slashes.json | 4 +- .../common/resources/resolving-null.json | 82 +++++++++++++++++++ 7 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 import-maps/common/resources/resolving-null.json diff --git a/import-maps/common/resolving.tentative.html b/import-maps/common/resolving.tentative.html index c947232e06322a..8dd3e3a2e710f5 100644 --- a/import-maps/common/resolving.tentative.html +++ b/import-maps/common/resolving.tentative.html @@ -15,6 +15,7 @@ 'resources/data-base-url.json', 'resources/scopes-exact-vs-prefix.json', 'resources/overlapping-entries.json', + 'resources/resolving-null.json', ]) { promise_test(() => runTestsFromJSON(json), diff --git a/import-maps/common/resources/parsing-addresses-absolute.json b/import-maps/common/resources/parsing-addresses-absolute.json index d392f8224faeb1..b4004395e7bb2b 100644 --- a/import-maps/common/resources/parsing-addresses-absolute.json +++ b/import-maps/common/resources/parsing-addresses-absolute.json @@ -51,6 +51,8 @@ "importMapBaseURL": "https://base.example/path1/path2/path3", "expectedParsedImportMap": { "imports": { + "unparseable2": null, + "unparseable3": null, "invalidButParseable1": "https://example.org/", "invalidButParseable2": "https://example.com///", "prettyNormal": "https://example.net/", diff --git a/import-maps/common/resources/parsing-addresses-invalid.json b/import-maps/common/resources/parsing-addresses-invalid.json index 7d6502a1bc485c..4e5f182df6aa31 100644 --- a/import-maps/common/resources/parsing-addresses-invalid.json +++ b/import-maps/common/resources/parsing-addresses-invalid.json @@ -13,7 +13,13 @@ }, "importMapBaseURL": "https://base.example/path1/path2/path3", "expectedParsedImportMap": { - "imports": {}, + "imports": { + "foo1": null, + "foo2": null, + "foo3": null, + "foo4": null, + "foo5": null + }, "scopes": {} } } diff --git a/import-maps/common/resources/parsing-addresses.json b/import-maps/common/resources/parsing-addresses.json index d5bb54f0c8073d..fe92709565e275 100644 --- a/import-maps/common/resources/parsing-addresses.json +++ b/import-maps/common/resources/parsing-addresses.json @@ -29,7 +29,11 @@ }, "importMapBaseURL": "data:text/html,test", "expectedParsedImportMap": { - "imports": {}, + "imports": { + "dotSlash": null, + "dotDotSlash": null, + "slash": null + }, "scopes": {} } }, @@ -65,7 +69,15 @@ }, "importMapBaseURL": "https://base.example/path1/path2/path3", "expectedParsedImportMap": { - "imports": {}, + "imports": { + "dotSlash1": null, + "dotDotSlash1": null, + "dotSlash2": null, + "dotDotSlash2": null, + "slash2": null, + "dotSlash3": null, + "dotDotSlash3": null + }, "scopes": {} } } diff --git a/import-maps/common/resources/parsing-schema-specifier-map.json b/import-maps/common/resources/parsing-schema-specifier-map.json index 926e7a1f5f73cd..7d7d4be2fe1392 100644 --- a/import-maps/common/resources/parsing-schema-specifier-map.json +++ b/import-maps/common/resources/parsing-schema-specifier-map.json @@ -18,6 +18,12 @@ }, "expectedParsedImportMap": { "imports": { + "null": null, + "boolean": null, + "number": null, + "object": null, + "array": null, + "array2": null, "string": "https://example.com/" }, "scopes": {} diff --git a/import-maps/common/resources/parsing-trailing-slashes.json b/import-maps/common/resources/parsing-trailing-slashes.json index 21e5faa13ec69c..89c454fc9f8bd7 100644 --- a/import-maps/common/resources/parsing-trailing-slashes.json +++ b/import-maps/common/resources/parsing-trailing-slashes.json @@ -7,7 +7,9 @@ }, "importMapBaseURL": "https://base.example/path1/path2/path3", "expectedParsedImportMap": { - "imports": {}, + "imports": { + "trailer/": null + }, "scopes": {} } } diff --git a/import-maps/common/resources/resolving-null.json b/import-maps/common/resources/resolving-null.json new file mode 100644 index 00000000000000..77563155d11dfc --- /dev/null +++ b/import-maps/common/resources/resolving-null.json @@ -0,0 +1,82 @@ +{ + "importMapBaseURL": "https://example.com/app/index.html", + "baseURL": "https://example.com/js/app.mjs", + "name": "Entries with errors shouldn't allow fallback", + "tests": { + "No fallback to less-specific prefixes": { + "importMap": { + "imports": { + "null/": "/1/", + "null/b/": null, + "null/b/c/": "/1/2/", + "invalid-url/": "/1/", + "invalid-url/b/": "https://:invalid-url:/", + "invalid-url/b/c/": "/1/2/", + "without-trailing-slashes/": "/1/", + "without-trailing-slashes/b/": "/x", + "without-trailing-slashes/b/c/": "/1/2/", + "prefix-resolution-error/": "/1/", + "prefix-resolution-error/b/": "data:text/javascript,/", + "prefix-resolution-error/b/c/": "/1/2/" + } + }, + "expectedResults": { + "null/x": "https://example.com/1/x", + "null/b/x": null, + "null/b/c/x": "https://example.com/1/2/x", + "invalid-url/x": "https://example.com/1/x", + "invalid-url/b/x": null, + "invalid-url/b/c/x": "https://example.com/1/2/x", + "without-trailing-slashes/x": "https://example.com/1/x", + "without-trailing-slashes/b/x": null, + "without-trailing-slashes/b/c/x": "https://example.com/1/2/x", + "prefix-resolution-error/x": "https://example.com/1/x", + "prefix-resolution-error/b/x": null, + "prefix-resolution-error/b/c/x": "https://example.com/1/2/x" + } + }, + "No fallback to less-specific scopes": { + "importMap": { + "imports": { + "null": "https://example.com/a", + "invalid-url": "https://example.com/b", + "without-trailing-slashes/": "https://example.com/c/", + "prefix-resolution-error/": "https://example.com/d/" + }, + "scopes": { + "/js/": { + "null": null, + "invalid-url": "https://:invalid-url:/", + "without-trailing-slashes/": "/x", + "prefix-resolution-error/": "data:text/javascript,/" + } + } + }, + "expectedResults": { + "null": null, + "invalid-url": null, + "without-trailing-slashes/x": null, + "prefix-resolution-error/x": null + } + }, + "No fallback to absolute URL parsing": { + "importMap": { + "imports": {}, + "scopes": { + "/js/": { + "https://example.com/null": null, + "https://example.com/invalid-url": "https://:invalid-url:/", + "https://example.com/without-trailing-slashes/": "/x", + "https://example.com/prefix-resolution-error/": "data:text/javascript,/" + } + } + }, + "expectedResults": { + "https://example.com/null": null, + "https://example.com/invalid-url": null, + "https://example.com/without-trailing-slashes/x": null, + "https://example.com/prefix-resolution-error/x": null + } + } + } +}