Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue with query string serialization

  • Loading branch information...
commit 442331244ac5f4b0615c7b5ec388ab6718657bec 1 parent a2e297d
@desunit desunit authored
View
2  src/ServiceStack.Text/Common/JsState.cs
@@ -10,5 +10,7 @@ internal static class JsState
[ThreadStatic] internal static bool IsWritingValue = false;
[ThreadStatic] internal static bool IsWritingDynamic = false;
+
+ [ThreadStatic] internal static bool QueryStringMode = false;
}
}
View
29 src/ServiceStack.Text/Common/WriteType.cs
@@ -283,23 +283,26 @@ public static void WriteProperties(TextWriter writer, object value)
public static void WriteQueryString(TextWriter writer, object value)
{
- var i = 0;
- foreach (var propertyWriter in PropertyWriters)
+ try
{
- var propertyValue = propertyWriter.GetterFn((T)value);
- if (propertyValue == null) continue;
- var propertyValueString = propertyValue as string;
- if (propertyValueString != null)
+ JsState.QueryStringMode = true;
+ var i = 0;
+ foreach (var propertyWriter in PropertyWriters)
{
- propertyValue = propertyValueString.UrlEncode();
- }
+ var propertyValue = propertyWriter.GetterFn((T) value);
+ if (propertyValue == null) continue;
- if (i++ > 0)
- writer.Write('&');
+ if (i++ > 0)
+ writer.Write('&');
- Serializer.WritePropertyName(writer, propertyWriter.PropertyName);
- writer.Write('=');
- propertyWriter.WriteFn(writer, propertyValue);
+ Serializer.WritePropertyName(writer, propertyWriter.PropertyName);
+ writer.Write('=');
+ propertyWriter.WriteFn(writer, propertyValue);
+ }
+ }
+ finally
+ {
+ JsState.QueryStringMode = false;
}
}
}
View
1  src/ServiceStack.Text/StringExtensions.cs
@@ -116,6 +116,7 @@ public static string EncodeJson(this string value)
public static string EncodeJsv(this string value)
{
+ if (JsState.QueryStringMode) value = UrlEncode(value);
return string.IsNullOrEmpty(value) || !JsWriter.HasAnyEscapeChars(value)
? value
: string.Concat
View
9 tests/ServiceStack.Text.Tests/QueryStringSerializerTests.cs
@@ -57,6 +57,15 @@ public void Can_serialize_newline()
Assert.That(QueryStringSerializer.SerializeToString(new {newline = "\r\n"}), Is.EqualTo("newline=%0d%0a"));
}
+ [Test]
+ public void Can_serialize_array_of_strings_with_colon()
+ {
+ var t = new List<string>();
+ t.Add("Foo:Bar");
+ t.Add("Get:Out");
+ Assert.That(QueryStringSerializer.SerializeToString(new { list = t }), Is.EqualTo("list=[Foo%3aBar,Get%3aOut]"));
+ }
+
[Test]
public void Can_serialize_tab()
{
Please sign in to comment.
Something went wrong with that request. Please try again.