Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita23473b

Browse files
committed
Merge pull requestjhnns#36 from claydotio/you-dont-even-want-to-know-how-long-this-took-to-find
Ignore invalid variable names during injection of global params
2 parents79aac24 +15dc51b commita23473b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

‎lib/getImportGlobalsSrc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ function getImportGlobalsSrc(ignore) {
2626
continue;
2727
}
2828
value=globalObj[key];
29-
src+="var "+key+" = global."+key+"; ";
29+
30+
// key may be an invalid variable name (e.g. 'a-b')
31+
try{
32+
eval("var "+key+";");
33+
src+="var "+key+" = global."+key+"; ";
34+
}catch(e){}
3035
}
3136

3237
returnsrc;
3338
}
3439

35-
module.exports=getImportGlobalsSrc;
40+
module.exports=getImportGlobalsSrc;

‎test/getImportGlobalsSrc.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ describe("getImportGlobalsSrc", function () {
1717
global.exports=exports;
1818
global.require=require;
1919

20+
// Also make sure it ignores invalid variable names
21+
global['a-b']=true;
22+
2023
src=getImportGlobalsSrc();
2124

2225
deleteglobal.module;
2326
deleteglobal.exports;
2427
deleteglobal.require;
28+
deleteglobal['a-b'];
2529

2630
expectedGlobals=Object.keys(global);
2731

@@ -63,4 +67,4 @@ describe("getImportGlobalsSrc", function () {
6367
expect(actualGlobals).to.eql(expectedGlobals);
6468
expect(actualGlobals.length).to.be.above(1);
6569
});
66-
});
70+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp