Fixed issue when the string is escaped with a newline

This commit is contained in:
smallmodel 2023-10-03 17:54:23 +02:00
parent 9f42da4686
commit b02abb1f18
No known key found for this signature in database
GPG key ID: A96F163ED4891440

View file

@ -92,43 +92,45 @@ static void TextEscapeValue( char *str, size_t len )
{ {
if( *str == '\\' ) if( *str == '\\' )
{ {
len--; if( len == 1 )
if( !len )
break; break;
str++; if( str[1] == 'n' )
if( *str == 'n' )
{ {
*to = '\n'; *to = '\n';
to++;
} }
else if( *str == 't' ) else if( str[1] == 't' )
{ {
*to = '\t'; *to = '\t';
to++;
} }
else if( *str == '"' ) else if( str[1] == '"' )
{ {
*to = '\"'; *to = '\"';
to++;
} }
else else
{ {
*to = *str; *to = str[1];
to++;
} }
len -= 2;
str += 2;
} }
else else
{ {
*to = *str; *to = *str;
to++;
len--;
str++;
} }
len--;
str++;
to++;
} }
*to = 0; *to = 0;
} }
static void TextValue( char *str, size_t len ) static void TextValue( char *str, size_t len )
{ {
char* s = parsetree_malloc(len + 1); char* s = parsetree_malloc(len + 1);
@ -186,7 +188,7 @@ static bool UseField( void )
%x VARIABLES %x VARIABLES
%x IDENTIFIER %x IDENTIFIER
string ([^\\\"]|\\.)* string ([^\\\"\r\n]|\\.)*
identifier [^\{\}\(\)\[\]\r\n\,:; \t] identifier [^\{\}\(\)\[\]\r\n\,:; \t]
alphanum [a-zA-Z0-9_]+ alphanum [a-zA-Z0-9_]+
varname [a-zA-Z0-9_\"]+ varname [a-zA-Z0-9_\"]+
@ -219,8 +221,8 @@ varname [a-zA-Z0-9_\"]+
unput(yytext[yyleng - 1]); unput(yytext[yyleng - 1]);
yyreducepos(1); yyreducepos(1);
} }
\"{string}\" { TextEscapeValue( yytext + 1, strlen( yytext ) - 2 ); YYLEX( TOKEN_STRING ); } \"{string}\" { TextEscapeValue( yytext + 1, yyleng - 2 ); YYLEX( TOKEN_STRING ); }
"?" { YYLEX( TOKEN_TERNARY ); } "?" { YYLEX( TOKEN_TERNARY ); }