From 0826de092f6e0c4b567af79646d133419b7001ec Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 13 Oct 2011 19:39:30 +0000 Subject: Fix double inclusion of host/port separator when login credentials are present. Add tests to tester. svn path=/trunk/netsurf/; revision=13040 --- utils/nsurl.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file 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 -- cgit v1.2.3