diff --git a/Test/Flurl.Test/UrlBuilderTests.cs b/Test/Flurl.Test/UrlBuilderTests.cs
index e0535121..19525f69 100644
--- a/Test/Flurl.Test/UrlBuilderTests.cs
+++ b/Test/Flurl.Test/UrlBuilderTests.cs
@@ -322,18 +322,19 @@ public void interprets_plus_as_space() {
Assert.AreEqual("1 2", url.QueryParams["x"]);
}
- [Test]
- public void can_encode_space_as_plus() {
- var url = new Url("http://www.mysite.com/foo+bar?x=1+2");
- Assert.AreEqual("http://www.mysite.com/foo+bar?x=1+2", url.ToString(true));
- }
-
[Test]
public void encodes_plus() {
var url = new Url("http://www.mysite.com").SetQueryParam("x", "1+2");
Assert.AreEqual("http://www.mysite.com?x=1%2B2", url.ToString());
}
+ [Test]
+ public void can_encode_space_as_plus() {
+ var url = new Url("http://www.mysite.com").AppendPathSegment("a b").SetQueryParam("c d", "1 2");
+ Assert.AreEqual("http://www.mysite.com/a%20b?c%20d=1%202", url.ToString()); // but not by default
+ Assert.AreEqual("http://www.mysite.com/a+b?c+d=1+2", url.ToString(true));
+ }
+
[TestCase("http://www.mysite.com/more", true)]
[TestCase("http://www.mysite.com/more?x=1&y=2", true)]
[TestCase("http://www.mysite.com/more?x=1&y=2#frag", true)]
@@ -393,14 +394,39 @@ public void constructor_parses_url_correctly(string full, string path, string qu
Assert.AreEqual(full, url.ToString());
}
-#if !NET40
// https://github.com/tmenier/Flurl/issues/185
[Test]
- public void can_encode_very_long_value() {
- // 65520 chars was the tipping point https://github.com/dotnet/corefx/issues/1936
- var s = new String('x', 1000000);
- Url.EncodeQueryParamValue(s, false);
+ public void can_encode_and_decode_very_long_value() {
+ // 65,520 chars is the tipping point for Uri.EscapeDataString https://github.com/dotnet/corefx/issues/1936
+ var len = 500000;
+
+ // every 10th char needs to be encoded
+ var s = string.Concat(Enumerable.Repeat("xxxxxxxxx ", len / 10));
+ Assert.AreEqual(len, s.Length); // just a sanity check
+
+ // encode space as %20
+ var encoded = Url.Encode(s, false);
+ // hex encoding will add 2 addtional chars for every char that needs to be encoded
+ Assert.AreEqual(len + (2 * len / 10), encoded.Length);
+ var expected = string.Concat(Enumerable.Repeat("xxxxxxxxx%20", len / 10));
+ Assert.AreEqual(expected, encoded);
+
+ var decoded = Url.Decode(encoded, false);
+ Assert.AreEqual(s, decoded);
+
+ // encode space as +
+ encoded = Url.Encode(s, true);
+ Assert.AreEqual(len, encoded.Length);
+ expected = string.Concat(Enumerable.Repeat("xxxxxxxxx+", len / 10));
+ Assert.AreEqual(expected, encoded);
+
+ // interpret + as space
+ decoded = Url.Decode(encoded, true);
+ Assert.AreEqual(s, decoded);
+
+ // don't interpret + as space, encoded and decoded should be the same
+ decoded = Url.Decode(encoded, false);
+ Assert.AreEqual(encoded, decoded);
}
-#endif
}
}
diff --git a/src/Flurl/Flurl.csproj b/src/Flurl/Flurl.csproj
index f9871dcd..dc91544a 100644
--- a/src/Flurl/Flurl.csproj
+++ b/src/Flurl/Flurl.csproj
@@ -4,7 +4,7 @@
net40;net45;netstandard1.3;netstandard1.0;
True
Flurl
- 2.5.2
+ 2.6.0
Todd Menier
A fluent, portable URL builder. To make HTTP calls off the fluent chain, check out Flurl.Http.
http://tmenier.github.io/Flurl
diff --git a/src/Flurl/QueryParameter.cs b/src/Flurl/QueryParameter.cs
index 73c89330..2ddad43a 100644
--- a/src/Flurl/QueryParameter.cs
+++ b/src/Flurl/QueryParameter.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Flurl.Util;
namespace Flurl
{
@@ -22,7 +23,7 @@ public QueryParameter(string name, object value, bool isEncoded = false) {
Name = name;
if (isEncoded && value != null) {
_encodedValue = value as string;
- _value = Url.DecodeQueryParamValue(_encodedValue);
+ _value = Url.Decode(_encodedValue, true);
}
else {
Value = value;
@@ -51,21 +52,21 @@ public object Value {
/// Indicates whether to encode space characters with "+" instead of "%20".
///
public string ToString(bool encodeSpaceAsPlus) {
- if (_encodedValue != null) {
- return $"{Name}={_encodedValue}";
- }
if (_value is IEnumerable && !(_value is string)) {
return string.Join("&",
from v in (_value as IEnumerable).Cast