Issue #338 occurs because the existing routines assume that any URI with an

extension is a file, and so links to TLD's ending with .pl, .au, etc., will
cause accessibility warnings. This fix attempts to distinguish between URI's
that are likely to be files versus links to domains.
This commit is contained in:
Jim Derry 2017-05-03 16:15:44 -04:00
parent d8839485a4
commit 8b2f92f625

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,8 +234,11 @@ static int IsSoundFile( ctmbstr sType )
{ {
uint i; uint i;
tmbchar ext[ 20 ]; tmbchar ext[ 20 ];
GetFileExtension( sType, ext, sizeof(ext) );
if ( !IsFilePath(sType) ) return 0;
GetFileExtension( sType, ext, sizeof(ext) );
for (i = 0; i < N_AUDIO_EXTS; i++) for (i = 0; i < N_AUDIO_EXTS; i++)
{ {
if ( TY_(tmbstrcasecmp)(ext, soundExtensions[i]) == 0 ) if ( TY_(tmbstrcasecmp)(ext, soundExtensions[i]) == 0 )
@ -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++)