forked from bblanchon/ArduinoJson
Fixed parsing of comments (issue #421)
This commit is contained in:
@ -1,6 +1,11 @@
|
|||||||
ArduinoJson: change log
|
ArduinoJson: change log
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
HEAD
|
||||||
|
----
|
||||||
|
|
||||||
|
* Fixed parsing of comments (issue #421)
|
||||||
|
|
||||||
v5.8.1
|
v5.8.1
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -27,39 +27,27 @@ void skipSpacesAndComments(TInput& input) {
|
|||||||
// C-style block comment
|
// C-style block comment
|
||||||
case '*':
|
case '*':
|
||||||
input.move(); // skip '/'
|
input.move(); // skip '/'
|
||||||
input.move(); // skip '*'
|
// no need to skip '*'
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (input.current()) {
|
|
||||||
case '\0':
|
|
||||||
return;
|
|
||||||
case '*':
|
|
||||||
input.move(); // skip '*'
|
|
||||||
if (input.current() == '/') {
|
|
||||||
input.move(); // skip '/'
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
input.move();
|
input.move();
|
||||||
|
if (input.current() == '\0') return;
|
||||||
|
if (input.current() == '*' && input.next() == '/') {
|
||||||
|
input.move(); // skip '*'
|
||||||
|
input.move(); // skip '/'
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// C++-style line comment
|
// C++-style line comment
|
||||||
case '/':
|
case '/':
|
||||||
input.move(); // skip '/'
|
// not need to skip "//"
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (input.current()) {
|
|
||||||
case '\0':
|
|
||||||
return;
|
|
||||||
case '\n':
|
|
||||||
input.move();
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
input.move();
|
input.move();
|
||||||
|
if (input.current() == '\0') return;
|
||||||
|
if (input.current() == '\n') break;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
return;
|
|
||||||
|
|
||||||
// not a comment, just a '/'
|
// not a comment, just a '/'
|
||||||
default:
|
default:
|
||||||
|
@ -287,7 +287,7 @@ TEST_F(JsonParser_Array_Tests, CCommentAfterComma) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_Array_Tests, CppCommentBeforeOpeningBracket) {
|
TEST_F(JsonParser_Array_Tests, CppCommentBeforeOpeningBracket) {
|
||||||
whenInputIs("//COMMENT\n[\"hello\"]");
|
whenInputIs("//COMMENT\n\t[\"hello\"]");
|
||||||
|
|
||||||
parseMustSucceed();
|
parseMustSucceed();
|
||||||
sizeMustBe(1);
|
sizeMustBe(1);
|
||||||
@ -303,7 +303,7 @@ TEST_F(JsonParser_Array_Tests, CppCommentAfterOpeningBracket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_Array_Tests, CppCommentBeforeClosingBracket) {
|
TEST_F(JsonParser_Array_Tests, CppCommentBeforeClosingBracket) {
|
||||||
whenInputIs("[\"hello\"//COMMENT\n]");
|
whenInputIs("[\"hello\"//COMMENT\r\n]");
|
||||||
|
|
||||||
parseMustSucceed();
|
parseMustSucceed();
|
||||||
sizeMustBe(1);
|
sizeMustBe(1);
|
||||||
|
Reference in New Issue
Block a user