From fd5ad500c5fc128549ff4dd55a0a7e611e482ce1 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 6 Oct 2011 11:53:23 +0000 Subject: Only need to cope with trailing whitespace if it exists. svn path=/trunk/netsurf/; revision=12969 --- utils/nsurl.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/utils/nsurl.c b/utils/nsurl.c index 9faf311d7..20dc10632 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -192,6 +192,7 @@ static void nsurl__get_string_markers(const char const *url_s, { const char *pos = url_s; /** current position in url_s */ bool is_http = false; + bool trailing_whitespace = false; /* Initialise marker set */ struct url_markers marker = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -363,18 +364,31 @@ static void nsurl__get_string_markers(const char const *url_s, /* We got to the end of url_s. * Need to skip back over trailing whitespace to find end of URL */ pos--; - while (isspace(*pos)) - pos--; + if (isspace(*pos)) { + trailing_whitespace = true; + while (isspace(*pos)) + pos--; + } + marker.end = pos + 1 - url_s; - /* Ensure last url section doesn't pass end */ - if (marker.fragment > marker.end) marker.fragment = marker.end; - if (marker.query > marker.end) marker.query = marker.end; - if (marker.path > marker.end) marker.path = marker.end; - if (marker.colon_last > marker.end) marker.colon_last = marker.end; - if (marker.at > marker.end) marker.at = marker.end; - if (marker.colon_last > marker.end) marker.colon_last = marker.end; - if (marker.fragment > marker.end) marker.fragment = marker.end; + if (trailing_whitespace == true) { + /* Ensure last url section doesn't pass end */ + if (marker.fragment > marker.end) + marker.fragment = marker.end; + if (marker.query > marker.end) + marker.query = marker.end; + if (marker.path > marker.end) + marker.path = marker.end; + if (marker.colon_last > marker.end) + marker.colon_last = marker.end; + if (marker.at > marker.end) + marker.at = marker.end; + if (marker.colon_last > marker.end) + marker.colon_last = marker.end; + if (marker.fragment > marker.end) + marker.fragment = marker.end; + } /* Got all the URL components pegged out now */ *markers = marker; -- cgit v1.2.3