Skip to content

Commit

Permalink
parameters escape
Browse files Browse the repository at this point in the history
  • Loading branch information
GioviQ committed Nov 17, 2020
1 parent 8823cdd commit 71982ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Breeze.Sharp/EntityQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ public override String GetResourcePath(MetadataStore metadataStore) {

/// <summary> Return the query as JSON url, e.g. "Customer?{where:{FirstName:'Maria'}}" </summary>
private string GetJsonResourcePath(string resourceName) {
var json = JsonQueryExpressionVisitor.Translate(this.Expression);
var json = JsonQueryExpressionVisitor.Translate(this.Expression, out string parameters);
if (json.Length > 2) {
// TODO may be able to get away with not escaping the URI
System.Diagnostics.Debug.WriteLine($"json query: {json}");
var uri = Uri.EscapeUriString(json);
return resourceName + '?' + uri;
return resourceName + '?' + uri + (parameters != null ? "&" + parameters : string.Empty);
} else {
return resourceName;
}
Expand Down
6 changes: 4 additions & 2 deletions Breeze.Sharp/Json/JsonQueryExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class JsonQueryExpressionVisitor : ExpressionVisitor {
private ListExpressionVisitor expandVisitor;

/// <summary> Translate the EntityQuery expression into a JSON string </summary>
public static string Translate(Expression expression) {
public static string Translate(Expression expression, out string parameters) {

var visitor = new JsonQueryExpressionVisitor();
visitor.VisitRoot(expression);
Expand All @@ -44,7 +44,9 @@ public static string Translate(Expression expression) {
//without a server-side custom model binder for 'Customer?{"parameters":{"companyName":"C"}}' I cannot have parameters with right values,
//so I have to use this hack
if (visitor.Parameters?.Count > 0)
json = json + "&" + string.Join("&", visitor.Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value)));
parameters = string.Join("&", visitor.Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, Uri.EscapeDataString(kvp.Value))));
else
parameters = null;

return json;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Internal/Tests/JsonQuerySerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void TearDown() {

// TODO somehow compare JSON by structure instead of string, so whitespace changes won't matter
private void Check(EntityQuery query, string expectedJson) {
var json = JsonQueryExpressionVisitor.Translate(query.Expression);
var json = JsonQueryExpressionVisitor.Translate(query.Expression, out string parameters);
Assert.AreEqual(expectedJson, json);
}

Expand Down

0 comments on commit 71982ca

Please sign in to comment.