From 3cc5e76f2d754d213cb896d1cc0dea5d43854b13 Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Tue, 4 Sep 2018 23:31:12 +0200 Subject: [PATCH] Support : Fixes for Verbatim Regeneration of URL String Form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A URL in string form should be able to be parsed and then verbatim regenerated according to 'UrlTest'. This change fixes this ability for the case where there is a '?' initiating a query or a '//' initiating a host/authority section. Partly Fixes #14377 Change-Id: I6547253c3cdc22d79514edf75284e9725d1a2d17 Reviewed-on: https://review.haiku-os.org/512 Reviewed-by: Jérôme Duval --- src/kits/support/Url.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/kits/support/Url.cpp b/src/kits/support/Url.cpp index 5ce7a457a4..d625d4f0ec 100644 --- a/src/kits/support/Url.cpp +++ b/src/kits/support/Url.cpp @@ -984,6 +984,7 @@ BUrl::_ExplodeUrlString(const BString& url) explode_url_parse_state state = EXPLODE_PROTOCOL; int32 offset = 0; int32 length = url.Length(); + bool forceHasHost = false; const char *url_c = url.String(); // The regexp is provided in RFC3986 (URI generic syntax), Appendix B @@ -1033,6 +1034,9 @@ BUrl::_ExplodeUrlString(const BString& url) // to parsing the path. if (strncmp(&url_c[offset], "//", 2) == 0) { state = EXPLODE_AUTHORITY; + // if we see the // then this would imply that a host is + // to be rendered even if no host has been parsed. + forceHasHost = true; offset += 2; } else { state = EXPLODE_PATH; @@ -1068,6 +1072,10 @@ BUrl::_ExplodeUrlString(const BString& url) offset, explode_is_request_char); SetRequest(BString(&url_c[offset], end_request - offset)); offset = end_request; + // if there is a "?" in the parse then it is clear that + // there is a 'request' / query present regardless if there + // are any valid key-value pairs. + fHasRequest = true; } state = EXPLODE_FRAGMENT; break; @@ -1091,6 +1099,9 @@ BUrl::_ExplodeUrlString(const BString& url) } } + if (forceHasHost) + fHasHost = true; + return B_OK; }