From 18dcf0c42fff69399b209afda8df7a165457aefe Mon Sep 17 00:00:00 2001 From: Matt Artist Date: Tue, 26 Nov 2024 14:45:31 -0500 Subject: [PATCH] feat: allow exact values This just disables the inline comment escaping --- ini.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ini.js b/ini.js index 70296f1..b343dee 100644 --- a/ini.js +++ b/ini.js @@ -17,6 +17,7 @@ const encode = (obj, options) => { whitespace: false, inlineArrays: false, allowEmptySection: false, + exactValue: false, }; }else{ options = options || Object.create(null); @@ -100,7 +101,12 @@ const decode = (str, options = {}) => { } let key = unsafe(match[2]); if(isConstructorOrProto(ref, key)){ continue; } - let value = match[3] ? unsafe(match[3]) : defaultValue; + let value = null; + if(options.exactValue){ + value = match[3]; + }else{ + value = match[3] ? unsafe(match[3]) : defaultValue; + } switch(value){ case 'true': case 'True': @@ -180,6 +186,10 @@ const safe = (val, key, options = {}) => { if(key && options.forceStringifyKeys && options.forceStringifyKeys.includes(key)){ return JSON.stringify(val); } + if(options.exactValue){ + // Don't try to escape a comment in a value + return val; + } // comments return val.replace(/;/g, '\\;').replace(/#/g, '\\#'); };