Issue #65 - avoid new quotes if in quotes

This commit is contained in:
Geoff McLane 2015-09-19 14:58:42 +02:00
parent 0386e0fa91
commit eda37c5adb

View file

@ -86,7 +86,7 @@ static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node )
int col = ( doc->lexer ? doc->lexer->columns : 0 ); int col = ( doc->lexer ? doc->lexer->columns : 0 );
SPRTF("R=%d C=%d: ", line, col ); SPRTF("R=%d C=%d: ", line, col );
// DEBUG: Be able to set a TRAP on a SPECIFIC row,col // DEBUG: Be able to set a TRAP on a SPECIFIC row,col
if ((line == 6) && (col == 33)) { if ((line == 4) && (col == 1)) {
check_me("Show_Node"); // just a debug trap check_me("Show_Node"); // just a debug trap
} }
if (lexer && lexer->token && (lexer->token->type == TextNode)) { if (lexer && lexer->token && (lexer->token->type == TextNode)) {
@ -1967,11 +1967,13 @@ static Bool IsInQuotesorComment( Lexer * lexer )
unsigned int i; unsigned int i;
Bool inq, toeol, toec; Bool inq, toeol, toec;
unsigned char prev, quot, c; unsigned char prev, quot, c;
tmbstr pnc;
prev = quot = 0; prev = quot = 0;
inq = toeol = toec = no; inq = toeol = toec = no;
for ( i = lexer->txtstart; i < lexer->lexsize; i++ ) for ( i = lexer->txtstart; i < lexer->lexsize; i++ )
{ {
c = lexer->lexbuf[i]; pnc = &lexer->lexbuf[i];
c = *pnc;
if ( toeol ) if ( toeol )
{ {
/* continue until END OF LINE */ /* continue until END OF LINE */
@ -1990,11 +1992,12 @@ static Bool IsInQuotesorComment( Lexer * lexer )
{ {
if (( prev != '\\' ) && (( c == '"' ) || ( c == '\'')) ) if (( prev != '\\' ) && (( c == '"' ) || ( c == '\'')) )
{ {
/* deal with 'unescaped' quote chars " or ' */
if ( inq && ( c == quot )) if ( inq && ( c == quot ))
{ {
inq = no; inq = no;
} }
else else if ( !inq ) /* 20150919: Oops no new 'quote' if already in a 'quote' */
{ {
inq = yes; inq = yes;
quot = c; /* keep type of start quote - single or double */ quot = c; /* keep type of start quote - single or double */
@ -2009,7 +2012,7 @@ static Bool IsInQuotesorComment( Lexer * lexer )
toec = yes; /* set until END OF COMMENT */ toec = yes; /* set until END OF COMMENT */
} }
} }
prev = c; prev = c;
} }
return (inq | toeol | toec); return (inq | toeol | toec);
} }