From c1a1ce23927cb160fedac358f5181fe01088ee03 Mon Sep 17 00:00:00 2001
From: Matt Artist <matthew.a@nodecraft.com>
Date: Wed, 27 Nov 2024 10:41:10 -0500
Subject: [PATCH] feat: handle common comment case

---
 ini.js      | 6 +++++-
 test/foo.js | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/ini.js b/ini.js
index 5e0161b..b2200f2 100644
--- a/ini.js
+++ b/ini.js
@@ -227,7 +227,11 @@ const unsafe = (val) => {
 			}
 			isEscaping = false;
 		}else if(commentChars.includes(char)){
-			break;
+			// Check if there's spaces around this comment character
+			// If there is, then we're done parsing at the character before this one
+			if(val.charAt(i - 1) === ' ' && val.charAt(i + 1) === ' '){
+				break;
+			}
 		}else if(char === '\\'){
 			isEscaping = true;
 		}else{
diff --git a/test/foo.js b/test/foo.js
index e40ec94..7e562b7 100644
--- a/test/foo.js
+++ b/test/foo.js
@@ -400,7 +400,7 @@ test('ignores invalid line (=)', function(t){
 
 test("unsafe escape values", function(t){
 	t.equal(ini.unsafe(''), '');
-	t.equal(ini.unsafe('x;y'), 'x');
+	t.equal(ini.unsafe('x;y'), 'xy');
 	t.equal(ini.unsafe('x  # y'), 'x');
 	t.equal(ini.unsafe('x "\\'), 'x "\\');
 	t.end();