Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7017 from rtsao/crossorigin-attr
Add script src origin check to ensure crossorigin attribute is only set when needed
- Loading branch information
Showing
9 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
it("should load script without crossorigin attribute (default)", function() { | ||
const promise = import("./empty?a" /* webpackChunkName: "crossorigin-default" */); | ||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./crossorigin-default.web.js"); | ||
expect(script.src).toBe("https://test.cases/path/crossorigin-default.web.js"); | ||
expect(script.crossOrigin).toBe(undefined); | ||
|
||
return promise; | ||
}); | ||
|
||
it("should load script without crossorigin attribute (relative)", function() { | ||
var originalValue = __webpack_public_path__; | ||
__webpack_public_path__ = "../"; | ||
const promise = import("./empty?b" /* webpackChunkName: "crossorigin-relative" */); | ||
__webpack_public_path__ = originalValue; | ||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./crossorigin-relative.web.js"); | ||
expect(script.src).toBe("https://test.cases/crossorigin-relative.web.js"); | ||
expect(script.crossOrigin).toBe(undefined); | ||
|
||
return promise; | ||
}); | ||
|
||
it("should load script without crossorigin attribute (server relative)", function() { | ||
var originalValue = __webpack_public_path__; | ||
__webpack_public_path__ = "/server/"; | ||
const promise = import("./empty?c" /* webpackChunkName: "crossorigin-server-relative" */); | ||
__webpack_public_path__ = originalValue; | ||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./crossorigin-server-relative.web.js"); | ||
expect(script.src).toBe("https://test.cases/server/crossorigin-server-relative.web.js"); | ||
expect(script.crossOrigin).toBe(undefined); | ||
|
||
return promise; | ||
}); | ||
|
||
it("should load script without crossorigin attribute (same origin)", function() { | ||
var originalValue = __webpack_public_path__; | ||
__webpack_public_path__ = "https://test.cases/"; | ||
const promise = import("./empty?d" /* webpackChunkName: "crossorigin-same-origin" */); | ||
__webpack_public_path__ = originalValue; | ||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./crossorigin-same-origin.web.js"); | ||
expect(script.src).toBe("https://test.cases/crossorigin-same-origin.web.js"); | ||
expect(script.crossOrigin).toBe(undefined); | ||
|
||
return promise; | ||
}); | ||
|
||
it("should load script with crossorigin attribute anonymous (different origin)", function() { | ||
var originalValue = __webpack_public_path__; | ||
__webpack_public_path__ = "https://example.com/"; | ||
const promise = import("./empty?e" /* webpackChunkName: "crossorigin-different-origin" */); | ||
__webpack_public_path__ = originalValue; | ||
|
||
|
||
var script = document.head._children.pop(); | ||
__non_webpack_require__("./crossorigin-different-origin.web.js"); | ||
expect(script.src).toBe("https://example.com/crossorigin-different-origin.web.js"); | ||
expect(script.crossOrigin).toBe("anonymous"); | ||
|
||
return promise; | ||
}); |
13 changes: 13 additions & 0 deletions
13
test/configCases/crossorigin/set-crossorigin/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
target: "web", | ||
output: { | ||
chunkFilename: "[name].web.js", | ||
crossOriginLoading: "anonymous" | ||
}, | ||
performance: { | ||
hints: false | ||
}, | ||
optimization: { | ||
minimize: false | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters