(trunk libT) fix ABR error when parsing a URL with no path and no trailing slash after the host. Error reported by livings124

This commit is contained in:
Jordan Lee 2011-04-05 22:21:18 +00:00
parent 4694f95594
commit f37da42a8c
2 changed files with 14 additions and 2 deletions

View File

@ -385,6 +385,16 @@ test_url( void )
char * str;
const char * url;
url = "http://1";
check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) );
check( !strcmp( scheme, "http" ) )
check( !strcmp( host, "1" ) )
check( !strcmp( path, "/" ) )
check( port == 80 )
tr_free( scheme );
tr_free( path );
tr_free( host );
url = "http://www.some-tracker.org/some/path";
check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) )
check( !strcmp( scheme, "http" ) )

View File

@ -1030,6 +1030,7 @@ tr_urlParse( const char * url_in,
host = pch;
host_len = n;
pch += n;
if( pch && *pch )
*pch++ = '\0';
/*fprintf( stderr, "host is [%s]... what's left is [%s]\n", host, pch );*/
if( havePort )
@ -1061,7 +1062,8 @@ tr_urlParse( const char * url_in,
if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host =
tr_strndup( host, host_len ); }
if( setme_path ){ if( path[0] == '/' ) *setme_path = tr_strdup( path );
if( setme_path ){ if( !*path ) *setme_path = tr_strdup( "/" );
else if( path[0] == '/' ) *setme_path = tr_strdup( path );
else { ( (char*)path )[-1] = '/'; *setme_path = tr_strdup( path - 1 ); } }
if( setme_port ) *setme_port = port;
}