From 2c2c4aa53bf3687fbf597e54107ec7a7837e3810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E9=9B=A8=E5=8D=97?= <18842920976@163.com> Date: Tue, 8 Jul 2025 13:27:07 +0800 Subject: [PATCH 1/2] add: parse function add (contents !== '' ) --- lib/nconf/stores/file.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/nconf/stores/file.js b/lib/nconf/stores/file.js index f5d1e8ba..0f88897d 100644 --- a/lib/nconf/stores/file.js +++ b/lib/nconf/stores/file.js @@ -205,7 +205,10 @@ File.prototype.stringify = function (format) { // `this.secure` is enabled. // File.prototype.parse = function (contents) { - var parsed = this.format.parse(contents); + var parsed = {}; + if (contents !== '') { + parsed = this.format.parse(contents); + } if (this.secure) { var self = this; From d6f60285c0b285b18254d2e718ef3f16f93f43a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E9=9B=A8=E5=8D=97?= <18842920976@163.com> Date: Tue, 8 Jul 2025 14:12:53 +0800 Subject: [PATCH 2/2] Optimization --- lib/nconf/stores/file.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/nconf/stores/file.js b/lib/nconf/stores/file.js index 0f88897d..fe35d602 100644 --- a/lib/nconf/stores/file.js +++ b/lib/nconf/stores/file.js @@ -206,7 +206,8 @@ File.prototype.stringify = function (format) { // File.prototype.parse = function (contents) { var parsed = {}; - if (contents !== '') { + if (typeof contents === 'string' && contents.trim() !== '') { + console.log('22222222') parsed = this.format.parse(contents); }