diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2011-10-13 19:39:30 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2011-10-13 19:39:30 +0000 |
commit | 0826de092f6e0c4b567af79646d133419b7001ec (patch) | |
tree | 8ba5373710ebec723d4bff41344974b7b2ba4fb5 | |
parent | eb9c223f9d61f700ec27cb10b1aa892cd8a2d766 (diff) | |
download | netsurf-0826de092f6e0c4b567af79646d133419b7001ec.tar.gz netsurf-0826de092f6e0c4b567af79646d133419b7001ec.tar.bz2 |
Fix double inclusion of host/port separator when login credentials are present. Add tests to tester.
svn path=/trunk/netsurf/; revision=13040
-rw-r--r-- | utils/nsurl.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/utils/nsurl.c b/utils/nsurl.c index b58f54274..c184758c9 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -815,10 +815,14 @@ static nserror nsurl__create_from_section(const char const *url_s, if (!(flags & NSURL_F_NO_PORT)) { /* There's a port */ - sec_start = norm_start + colon - pegs->at + 1; + size_t skip = (pegs->at == pegs->authority) ? + 1 : 0; + sec_start = norm_start + colon - pegs->at + + skip; if (flags & NSURL_F_IS_HTTP && length - - (colon - pegs->at + 1) == 2 && + (colon - pegs->at + skip) == + 2 && *sec_start == '8' && *(sec_start + 1) == '0') { /* Scheme is http, and port is default @@ -833,16 +837,19 @@ static nserror nsurl__create_from_section(const char const *url_s, } /* Add non-redundant ports to NetSurf URL */ - sec_start = norm_start + colon - pegs->at + 1; + sec_start = norm_start + colon - pegs->at + + skip; if (!(flags & NSURL_F_NO_PORT) && lwc_intern_string(sec_start, - length - (colon - pegs->at + 1), + length - + (colon - pegs->at + skip), &url->port) != lwc_error_ok) { return NSERROR_NOMEM; } /* update length for host */ - length = colon - pegs->at; + skip = (pegs->at == pegs->authority) ? 0 : 1; + length = colon - pegs->at - skip; } /* host */ @@ -1004,6 +1011,7 @@ void nsurl__test(void) int index = 0; char *string; size_t len; + const char *url; /* Create base URL */ if (nsurl_create("http://a/b/c/d;p?q", &base) != NSERROR_OK) { @@ -1049,6 +1057,44 @@ void nsurl__test(void) nsurl_unref(base); } + + /* Other tests */ + + url = "http://www.netsurf-browser.org:8080/"; + if (nsurl_create(url, &base) != NSERROR_OK) { + LOG(("Failed to create URL:\n\t\t%s.", url)); + + } else { + if (strcmp(nsurl_access(base), url) != 0) + LOG(("FAIL:\n\t\t%s\n\t\t--> %s", + url, nsurl_access(base))); + + nsurl_unref(base); + } + + url = "http://user@www.netsurf-browser.org:8080/hello"; + if (nsurl_create(url, &base) != NSERROR_OK) { + LOG(("Failed to create URL:\n\t\t%s.", url)); + + } else { + if (strcmp(nsurl_access(base), url) != 0) + LOG(("FAIL:\n\t\t%s\n\t\t--> %s", + url, nsurl_access(base))); + + nsurl_unref(base); + } + + url = "http://user:password@www.netsurf-browser.org:8080/hello"; + if (nsurl_create(url, &base) != NSERROR_OK) { + LOG(("Failed to create URL:\n\t\t%s.", url)); + + } else { + if (strcmp(nsurl_access(base), url) != 0) + LOG(("FAIL:\n\t\t%s\n\t\t--> %s", + url, nsurl_access(base))); + + nsurl_unref(base); + } } #endif |