mirror of https://github.com/noisymime/Arduino.git
Enforcing string start/end check. See #1687
This commit is contained in:
parent
139dd6bf6a
commit
e6698e4baa
|
@ -327,6 +327,25 @@ public class PdePreprocessor {
|
||||||
return functionMatches;
|
return functionMatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isStartOrEndOfString(char p[], int index) {
|
||||||
|
if (p[index] != '\"') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p[index - 1] == '\\') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index - 2 >= 0 && p[index - 2] == '\\') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace all commented portions of a given String as spaces.
|
* Replace all commented portions of a given String as spaces.
|
||||||
|
@ -338,7 +357,7 @@ public class PdePreprocessor {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
boolean insideString = false;
|
boolean insideString = false;
|
||||||
while (index < p.length) {
|
while (index < p.length) {
|
||||||
if (p[index] == '\"') {
|
if (isStartOrEndOfString(p, index)) {
|
||||||
insideString = !insideString;
|
insideString = !insideString;
|
||||||
}
|
}
|
||||||
// for any double slash comments, ignore until the end of the line
|
// for any double slash comments, ignore until the end of the line
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
|
// "comment with a double quote
|
||||||
|
/* \" other comment with double quote */
|
||||||
Serial.println("Accept: */*");
|
Serial.println("Accept: */*");
|
||||||
|
Serial.println("Accept: \" */*");
|
||||||
|
Serial.println("Accept: \\"); // */*");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Serial.println( );
|
||||||
|
Serial.println( );
|
||||||
Serial.println( );
|
Serial.println( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue