From 7cc97d98213436350624bcf5c38203b3116ca651 Mon Sep 17 00:00:00 2001
From: Richard Walters <rwalters@digitalstirling.com>
Date: Thu, 28 Mar 2019 00:00:15 -0700
Subject: Percent-encode '+' in the query portion

---
 test/src/UriTests.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

(limited to 'test')

diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 637bfb7..e3737c2 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -906,3 +906,16 @@ TEST(UriTests, ClearQuery) {
     EXPECT_EQ("http://www.example.com/", uri.GenerateString());
     EXPECT_FALSE(uri.HasQuery());
 }
+
+TEST(UriTests, PercentEncodePlusInQueries) {
+    // Although RFC 3986 doesn't say anything about '+', some web services
+    // treat it the same as ' ' due to how HTML originally defined how
+    // to encode the query portion of a URL
+    // (see https://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-or-20).
+    //
+    // To avoid issues with these web services, make sure '+' is
+    // percent-encoded in a URI when the URI is encoded.
+    Uri::Uri uri;
+    uri.SetQuery("foo+bar");
+    EXPECT_EQ("?foo%2Bbar", uri.GenerateString());
+}
-- 
cgit v1.2.3