Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified logo.pdn
Binary file not shown.
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/GraphQL.Query.Builder/QueryStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void Clear()
/// - Key value pair: `foo:"bar"` or `foo:10` ...
/// - List: `["foo","bar"]` or `[1,2]` ...
/// - Dictionary: `{foo:"bar",b:10}`
/// - Object: `{foo:"bar",b:10}`
/// </summary>
/// <param name="value"></param>
/// <returns>The formatted query param.</returns>
Expand All @@ -54,7 +55,8 @@ internal protected virtual string FormatQueryParam(object value)
switch (value)
{
case string strValue:
return "\"" + strValue + "\"";
string encoded = strValue.Replace("\"", "\\\"");
return $"\"{encoded}\"";

case byte byteValue:
return byteValue.ToString();
Expand Down
11 changes: 10 additions & 1 deletion tests/GraphQL.Query.Builder.UnitTests/QueryStringBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public void TestFormatQueryParam_string()
Assert.Equal("\"value\"", new QueryStringBuilder().FormatQueryParam(value));
}

[Fact]
public void TestFormatQueryParam_string_json()
{
string value = "{\"foo\":\"bar\",\"array\":[1,2]}";
Assert.Equal(
"\"{\\\"foo\\\":\\\"bar\\\",\\\"array\\\":[1,2]}\"",
new QueryStringBuilder().FormatQueryParam(value));
}

[Fact]
public void TestFormatQueryParam_byte()
{
Expand Down Expand Up @@ -265,7 +274,7 @@ public void TestFormatQueryParam_Object()
};

Assert.Equal("{Age:10,Name:\"Test\",Orders:[{Product:{load:{weight:45},name:\"Truck 1\",wheelsNumber:6}}]}", new QueryStringBuilder().FormatQueryParam(@object));

// with inner object with null property
@object = new Customer
{
Expand Down