Skip to content

Commit

Permalink
use only alias field properties
Browse files Browse the repository at this point in the history
prevent checking object prototype properties
  • Loading branch information
vankop committed Apr 4, 2022
1 parent c960801 commit b16c35c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/AliasFieldPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ module.exports = class AliasFieldPlugin {
);
return callback();
}
const data1 = fieldData[innerRequest];
const data2 = fieldData[innerRequest.replace(/^\.\//, "")];
const data = typeof data1 !== "undefined" ? data1 : data2;
const data = Object.prototype.hasOwnProperty.call(
fieldData,
innerRequest
)
? fieldData[innerRequest]
: Object.prototype.hasOwnProperty.call(
fieldData,
innerRequest.replace(/^\.\//, "")
)
? fieldData[innerRequest.slice(2)]
: undefined;
if (data === innerRequest) return callback();
if (data === undefined) return callback();
if (data === false) {
Expand Down
6 changes: 6 additions & 0 deletions test/browserField.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ describe("browserField", function () {
.resolveSync({}, p(), "./lib/main2.js")
.should.be.eql(p("lib", "browser.js"));
});

it("should check only alias field properties", () => {
resolver
.resolveSync({}, p(), "./toString")
.should.be.eql(p("lib", "toString.js"));
});
});
Empty file.
1 change: 1 addition & 0 deletions test/fixtures/browser-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"./lib/replaced.js": "./lib/browser",
"module-a": "./browser/module-a.js",
"module-b": "module-c",
"./toString": "./lib/toString.js",
".": false
},
"innerBrowser1": {
Expand Down

0 comments on commit b16c35c

Please sign in to comment.