Skip to content

Commit 3a524f1

Browse files
committed
Issue #207 - deal with 2 cases of an unambiguous ampersand.
html5 allows a naked ampersand unquoted, and now tidy will not issue a warning. This only deals with a & b, and P&<li>O</li> More may need to be done for other cases.
1 parent b65988c commit 3a524f1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/lexer.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,17 @@ static void ParseEntity( TidyDocImpl* doc, GetTokenMode mode )
10551055
if (semicolon)
10561056
TY_(AddCharToLexer)( lexer, ';' );
10571057
}
1058-
else /* naked & */
1059-
TY_(ReportEntityError)( doc, UNESCAPED_AMPERSAND,
1058+
else
1059+
{
1060+
/*\
1061+
* Issue #207 - A naked & is allowed in HTML5, as an unambiguous ampersand!
1062+
\*/
1063+
if (TY_(HTMLVersion)(doc) != HT50)
1064+
{
1065+
TY_(ReportEntityError)( doc, UNESCAPED_AMPERSAND,
10601066
lexer->lexbuf+start, ch );
1067+
}
1068+
}
10611069
}
10621070
else
10631071
{

src/pprint.c

+8
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,14 @@ static void PPrintText( TidyDocImpl* doc, uint mode, uint indent,
982982
ixWS = TextStartsWithWhitespace( doc->lexer, node, ix+1, mode );
983983
ix = IncrWS( ix, end, indent, ixWS );
984984
}
985+
else if (( c == '&' ) && (TY_(HTMLVersion)(doc) == HT50) &&
986+
(((ix + 1) == end) || ((ix + 1) < end) && (isspace(doc->lexer->lexbuf[ix+1]))) )
987+
{
988+
/*\
989+
* Issue #207 - This is an unambiguous ampersand need not be 'quoted' in HTML5
990+
\*/
991+
PPrintChar( doc, c, (mode | CDATA) );
992+
}
985993
else
986994
{
987995
PPrintChar( doc, c, mode );

0 commit comments

Comments
 (0)