Part 2.1 - Bug fixes and warning

This commit is contained in:
Marcos Caceres 2016-10-05 20:14:18 +11:00
parent cfc22ac46e
commit 2d7ddfef94

View file

@ -1697,29 +1697,31 @@ Bool TY_(TidyMetaCharset)(TidyDocImpl* doc)
AttVal *httpEquivAttr = TY_(AttrGetById)(node, TidyAttr_HTTP_EQUIV); AttVal *httpEquivAttr = TY_(AttrGetById)(node, TidyAttr_HTTP_EQUIV);
if(!charsetAttr && !httpEquivAttr) if(!charsetAttr && !httpEquivAttr)
continue; continue;
// Meta charset comes in quite a few flavors: // Meta charset comes in quite a few flavors:
// 1. <meta charset=value> - expected for (X)HTML5. // 1. <meta charset=value> - expected for (X)HTML5.
if (charsetAttr && !httpEquivAttr) if (charsetAttr && !httpEquivAttr)
{ {
// we already found one // we already found one, so remove the rest.
if(charsetFound) if(charsetFound)
{ {
Node *prevNode = node->prev;
TY_(ReportError)(doc, head, node, DISCARDING_UNEXPECTED);
TY_(DiscardElement)( doc, node ); TY_(DiscardElement)( doc, node );
printf("WARNING ABOUT DISCARDING ELEMENT \n"); node = prevNode;
continue; continue;
} }
charsetFound = yes; charsetFound = yes;
tmbstr lCharset = TY_(tmbstrtolower)(charsetAttr->value); tmbstr lCharset = TY_(tmbstrtolower)(charsetAttr->value);
if(strcmp(lCharset, enc) == 0) // Fix mismatched attribute value
if(strcmp(lCharset, enc) != 0)
{ {
// Move it to head tmbstr newValue = (tmbstr) TidyDocAlloc( doc, TY_(tmbstrlen)(enc) );
TY_(RemoveNode)( node ); TY_(tmbstrcpy)( newValue, enc );
TY_(InsertNodeAtStart)( head, node ); charsetAttr->value = newValue;
TY_(ReportError)( doc, head, node, BAD_ATTRIBUTE_VALUE_REPLACED );
} }
else // Make sure it's the first element.
{ if ( node != head->next ){
printf("WARN ABOUT MISMATCH: %s not match output %s \n", lCharset, enc);
TY_(RemoveNode)( node ); TY_(RemoveNode)( node );
TY_(InsertNodeAtStart)( head, node ); TY_(InsertNodeAtStart)( head, node );
} }