diff options
author | Joshua Oreman <oremanj@rwcr.net> | 2009-12-29 22:36:04 -0500 |
---|---|---|
committer | Marty Connor <mdc@etherboot.org> | 2010-01-20 18:14:28 -0500 |
commit | 3d9dd93a1452e28c728483b03e352691238491ed (patch) | |
tree | 73a41396fd514d12dbd7bd69ebfc49810bf73c7c /src/tests | |
parent | ef9d1a32c6dc83d1086141c18d2be19a05ab8e49 (diff) | |
download | ipxe-3d9dd93a1452e28c728483b03e352691238491ed.zip ipxe-3d9dd93a1452e28c728483b03e352691238491ed.tar.gz ipxe-3d9dd93a1452e28c728483b03e352691238491ed.tar.bz2 |
[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>
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/uri_test.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/tests/uri_test.c b/src/tests/uri_test.c index 2548760..ca3aed9 100644 --- a/src/tests/uri_test.c +++ b/src/tests/uri_test.c @@ -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 ); |