Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit ab7445f

Browse files
committed
[Fixes #9] Use a common query string builder api
1. Added a reference to Microsoft.AspNet.WebUtilities. 2. Refactored TemplateBinder to use QueryBuilder instead of manually creating a query string.
1 parent 30084b0 commit ab7445f

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Globalization;
99
using System.Text;
1010
using System.Text.RegularExpressions;
11+
using Microsoft.AspNet.WebUtilities;
1112

1213
namespace Microsoft.AspNet.Routing.Template
1314
{
@@ -241,7 +242,7 @@ public string BindValues(IDictionary<string, object> acceptedValues)
241242
encoded.Append(UriEncode(context.Build()));
242243

243244
// Generate the query string from the remaining values
244-
var firstParam = true;
245+
var queryBuilder = new QueryBuilder();
245246
foreach (var kvp in acceptedValues)
246247
{
247248
if (_defaults != null && _defaults.ContainsKey(kvp.Key))
@@ -256,14 +257,10 @@ public string BindValues(IDictionary<string, object> acceptedValues)
256257
continue;
257258
}
258259

259-
encoded.Append(firstParam ? '?' : '&');
260-
firstParam = false;
261-
262-
encoded.Append(Uri.EscapeDataString(kvp.Key));
263-
encoded.Append('=');
264-
encoded.Append(Uri.EscapeDataString(converted));
260+
queryBuilder.Add(kvp.Key, converted);
265261
}
266262

263+
encoded.Append(queryBuilder.ToString());
267264
return encoded.ToString();
268265
}
269266

src/Microsoft.AspNet.Routing/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {
77
"Microsoft.AspNet.Http": "1.0.0-*",
88
"Microsoft.AspNet.RequestContainer": "1.0.0-*",
9+
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
910
"Microsoft.Framework.DependencyInjection" : "1.0.0-*",
1011
"Microsoft.Framework.Logging": "1.0.0-*",
1112
"Microsoft.Framework.OptionsModel": "1.0.0-*"

0 commit comments

Comments
 (0)