mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 19:49:45 +03:00
[uri] Decode/encode URIs when parsing/unparsing
Currently, handling of URI escapes is ad-hoc; escaped strings are stored as-is in the URI structure, and it is up to the individual protocol to unescape as necessary. This is error-prone and expensive in terms of code size. Modify this behavior by unescaping in parse_uri() and escaping in unparse_uri() those fields that typically handle URI escapes (hostname, user, password, path, query, fragment), and allowing unparse_uri() to accept a subset of fields to print so it can be easily used to generate e.g. the escaped HTTP path?query request. Signed-off-by: Joshua Oreman <oremanj@rwcr.net> Signed-off-by: Marty Connor <mdc@etherboot.org>
This commit is contained in:
committed by
Marty Connor
parent
ef9d1a32c6
commit
3d9dd93a14
@@ -22,6 +22,9 @@ static struct uri_test uri_tests[] = {
|
||||
"http://etherboot.org/page3" },
|
||||
{ "tftp://192.168.0.1/", "/tftpboot/vmlinuz",
|
||||
"tftp://192.168.0.1/tftpboot/vmlinuz" },
|
||||
{ "ftp://the%41nswer%3d:%34ty%32wo@ether%62oot.org:8080/p%41th/foo",
|
||||
"to?%41=b#%43d",
|
||||
"ftp://theAnswer%3d:4ty2wo@etherboot.org:8080/path/to?a=b#cd" },
|
||||
#if 0
|
||||
"http://www.etherboot.org/wiki",
|
||||
"mailto:bob@nowhere.com",
|
||||
@@ -41,7 +44,7 @@ static int test_parse_unparse ( const char *uri_string ) {
|
||||
rc = -ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
len = unparse_uri ( buf, sizeof ( buf ), uri );
|
||||
len = unparse_uri ( buf, sizeof ( buf ), uri, URI_ALL );
|
||||
|
||||
/* Compare result */
|
||||
if ( strcmp ( buf, uri_string ) != 0 ) {
|
||||
@@ -92,7 +95,7 @@ static int test_resolve ( const char *base_uri_string,
|
||||
}
|
||||
|
||||
/* Compare result */
|
||||
len = unparse_uri ( buf, sizeof ( buf ), resolved_uri );
|
||||
len = unparse_uri ( buf, sizeof ( buf ), resolved_uri, URI_ALL );
|
||||
if ( strcmp ( buf, resolved_uri_string ) != 0 ) {
|
||||
printf ( "Resolution of \"%s\"+\"%s\" produced \"%s\"\n",
|
||||
base_uri_string, relative_uri_string, buf );
|
||||
|
||||
Reference in New Issue
Block a user