Merge pull request #541 from htacg/issue_338

Issue #338 - fix 3 spurious access level 3 warnings...
This commit is contained in:
Geoff McLane 2017-05-06 15:20:55 +02:00 committed by GitHub
commit 6839dfe601

View file

@ -131,6 +131,49 @@ static void MetaDataPresent( TidyDocImpl* doc, Node* node );
static void CheckEmbed( TidyDocImpl* doc, Node* node ); static void CheckEmbed( TidyDocImpl* doc, Node* node );
static void CheckListUsage( TidyDocImpl* doc, Node* node ); static void CheckListUsage( TidyDocImpl* doc, Node* node );
/*
IsFilePath attempts to determine whether or not the URI indicated
by path is a file rather than a TLD. For example, sample.com.au might
be confused with an audio file.
*/
static Bool IsFilePath( ctmbstr path )
{
const char *p = path;
char c;
typedef enum states { initial, protocol_found, slash_found, file_found } states;
states state = initial;
while ( ( c = *p++ ) != 0 && state != file_found )
{
switch ( state )
{
case initial:
if ( c == ':' )
state = protocol_found;
break;
case protocol_found:
if ( c =='/' )
state = slash_found;
break;
case slash_found:
if ( c =='/' )
state = protocol_found;
else
state = file_found;
break;
default:
break;
}
}
return state == file_found || state == initial;
}
/* /*
GetFileExtension takes a path and returns the extension GetFileExtension takes a path and returns the extension
portion of the path (if any). portion of the path (if any).
@ -163,9 +206,10 @@ static void GetFileExtension( ctmbstr path, tmbchar *ext, uint maxExt )
static Bool IsImage( ctmbstr iType ) static Bool IsImage( ctmbstr iType )
{ {
uint i; uint i;
/* Get the file extension */
tmbchar ext[20]; tmbchar ext[20];
if ( !IsFilePath(iType) ) return 0;
GetFileExtension( iType, ext, sizeof(ext) ); GetFileExtension( iType, ext, sizeof(ext) );
/* Compare it to the array of known image file extensions */ /* Compare it to the array of known image file extensions */
@ -190,6 +234,9 @@ static int IsSoundFile( ctmbstr sType )
{ {
uint i; uint i;
tmbchar ext[ 20 ]; tmbchar ext[ 20 ];
if ( !IsFilePath(sType) ) return 0;
GetFileExtension( sType, ext, sizeof(ext) ); GetFileExtension( sType, ext, sizeof(ext) );
for (i = 0; i < N_AUDIO_EXTS; i++) for (i = 0; i < N_AUDIO_EXTS; i++)
@ -215,6 +262,9 @@ static Bool IsValidSrcExtension( ctmbstr sType )
{ {
uint i; uint i;
tmbchar ext[20]; tmbchar ext[20];
if ( !IsFilePath(sType) ) return 0;
GetFileExtension( sType, ext, sizeof(ext) ); GetFileExtension( sType, ext, sizeof(ext) );
for (i = 0; i < N_FRAME_EXTS; i++) for (i = 0; i < N_FRAME_EXTS; i++)
@ -237,6 +287,9 @@ static Bool IsValidMediaExtension( ctmbstr sType )
{ {
uint i; uint i;
tmbchar ext[20]; tmbchar ext[20];
if ( !IsFilePath(sType) ) return 0;
GetFileExtension( sType, ext, sizeof(ext) ); GetFileExtension( sType, ext, sizeof(ext) );
for (i = 0; i < N_MEDIA_EXTS; i++) for (i = 0; i < N_MEDIA_EXTS; i++)
@ -2708,6 +2761,10 @@ static Bool CheckMetaData( TidyDocImpl* doc, Node* node, Bool HasMetaData )
TY_(ReportAccessError)( doc, node, REMOVE_AUTO_REDIRECT); TY_(ReportAccessError)( doc, node, REMOVE_AUTO_REDIRECT);
} }
} }
if (TY_(IsHTML5Mode)(doc) && attrIsCHARSET(av) && hasValue(av))
{
ContainsAttr = yes;
}
} }
if ( HasContent || HasHttpEquiv ) if ( HasContent || HasHttpEquiv )
@ -2787,10 +2844,18 @@ static void CheckDocType( TidyDocImpl* doc )
if (DTnode && DTnode->end != 0) if (DTnode && DTnode->end != 0)
{ {
ctmbstr word = textFromOneNode( doc, DTnode); ctmbstr word = textFromOneNode( doc, DTnode);
if ((strstr (word, "HTML PUBLIC") == NULL) && if (TY_(IsHTML5Mode)(doc))
(strstr (word, "html PUBLIC") == NULL)) {
if ((strstr(word, "HTML") == NULL) &&
(strstr(word, "html") == NULL))
DTnode = NULL; DTnode = NULL;
} }
else {
if ((strstr(word, "HTML PUBLIC") == NULL) &&
(strstr(word, "html PUBLIC") == NULL))
DTnode = NULL;
}
}
if (!DTnode) if (!DTnode)
TY_(ReportAccessError)( doc, &doc->root, DOCTYPE_MISSING); TY_(ReportAccessError)( doc, &doc->root, DOCTYPE_MISSING);
} }