aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-10-24 13:39:43 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-10-24 13:39:43 -0700
commitc94c7f3f8eef94b381e6e0e30ab58e7290594193 (patch)
tree49f5387c73240b276615069d9bb8c067b36fdcf9
parentaf0ecec183116e5feb4f8c9b4e963d05128479fa (diff)
Uri: fix bugs in copying and comparing URIs with query/fragment parts
Copying query or fragment needs to copy the "hasQuery" and "hasFragment" flags. Comparing URIs should make use of "hasQuery" and "hasFragment" to properly compare URIs that might not have query and/or fragment parts.
-rw-r--r--src/Uri.cpp18
-rw-r--r--test/src/UriTests.cpp2
2 files changed, 18 insertions, 2 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp
index fb9e1f8..4530595 100644
--- a/src/Uri.cpp
+++ b/src/Uri.cpp
@@ -1158,6 +1158,7 @@ namespace Uri {
* This is the other URI from which to copy the query.
*/
void CopyQuery(const Uri& other) {
+ hasQuery = other.impl_->hasQuery;
query = other.impl_->query;
}
@@ -1169,6 +1170,7 @@ namespace Uri {
* This is the other URI from which to copy the query.
*/
void CopyFragment(const Uri& other) {
+ hasFragment = other.impl_->hasFragment;
fragment = other.impl_->fragment;
}
@@ -1223,8 +1225,20 @@ namespace Uri {
)
)
&& (impl_->path == other.impl_->path)
- && (impl_->query == other.impl_->query)
- && (impl_->fragment == other.impl_->fragment)
+ && (
+ (!impl_->hasQuery && !other.impl_->hasQuery)
+ || (
+ (impl_->hasQuery && other.impl_->hasQuery)
+ && (impl_->query == other.impl_->query)
+ )
+ )
+ && (
+ (!impl_->hasFragment && !other.impl_->hasFragment)
+ || (
+ (impl_->hasFragment && other.impl_->hasFragment)
+ && (impl_->fragment == other.impl_->fragment)
+ )
+ )
);
}
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 75693cc..a57dea1 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -688,6 +688,8 @@ TEST(UriTests, ReferenceResolution) {
{"http://example.com/", "/foo", "http://example.com/foo"},
{"http://example.com", "/foo/", "http://example.com/foo/"},
{"http://example.com/", "/foo/", "http://example.com/foo/"},
+ {"http://example.com/", "?foo", "http://example.com/?foo"},
+ {"http://example.com/", "#foo", "http://example.com/#foo"},
};
size_t index = 0;
for (const auto& testVector : testVectors) {