Skip to content

Commit 3ae6282

Browse files
优化json解析。
1 parent db7b0f9 commit 3ae6282

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

packages/core/src/config/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ function _getConfig () {
475475
return {}
476476
}
477477

478+
if (!fs.existsSync(configFilePath)) {
479+
return {}
480+
}
481+
478482
return jsonApi.parse(fs.readFileSync(configFilePath))
479483
}
480484

packages/mitmproxy/src/json.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ if (JSON5.default) {
66

77
module.exports = {
88
parse (str) {
9+
if (str == null || str.length < 2) {
10+
return {}
11+
}
912
return JSON5.parse(str)
1013
},
1114
stringify (obj) {

0 commit comments

Comments
 (0)