Skip to content

Commit 532a6be

Browse files
committed
Fix handling of malformed block comments
Fixes #51 Closes #65
1 parent ba1182c commit 532a6be

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,9 @@ export default function stripJsonComments(jsonString, {whitespace = true, traili
105105
}
106106
}
107107

108-
return result + buffer + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
108+
const remaining = (isInsideComment === singleComment)
109+
? strip(jsonString, offset)
110+
: jsonString.slice(offset);
111+
112+
return result + buffer + remaining;
109113
}

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test('strips trailing commas', t => {
7474
t.is(stripJsonComments('{\n "array": [\n true,\n false /* comment */ ,\n /*comment*/ ],\n}', {trailingCommas: true, whitespace: false}), '{\n "array": [\n true,\n false \n ]\n}');
7575
});
7676

77-
test.failing('handles malformed block comments', t => {
77+
test('handles malformed block comments', t => {
7878
t.is(stripJsonComments('[] */'), '[] */');
7979
t.is(stripJsonComments('[] /*'), '[] /*'); // Fails
8080
});

0 commit comments

Comments
 (0)