From 124d86cb0feddacd38cce5feb1d394d3ce389fe1 Mon Sep 17 00:00:00 2001 From: tmenier Date: Fri, 21 Feb 2014 00:02:08 -0600 Subject: [PATCH] rename Add -> Set --- Flurl/StringExtensions.cs | 6 +++--- Flurl/Url.cs | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Flurl/StringExtensions.cs b/Flurl/StringExtensions.cs index fd90c3d..a2bced8 100644 --- a/Flurl/StringExtensions.cs +++ b/Flurl/StringExtensions.cs @@ -54,7 +54,7 @@ namespace Flurl /// value of query string parameter /// The Url obect with the query string parameter added public static Url AddQueryParam(this string url, string name, object value) { - return new Url(url).AddQueryParam(name, value); + return new Url(url).SetQueryParam(name, value); } /// @@ -64,7 +64,7 @@ namespace Flurl /// Typically an anonymous object, ie: new { x = 1, y = 2 } /// The Url object with the query string parameters added public static Url AddQueryParams(this string url, object values) { - return new Url(url).AddQueryParams(values); + return new Url(url).SetQueryParams(values); } /// @@ -74,7 +74,7 @@ namespace Flurl /// Dictionary of key/value pairs to add to the query string /// The Url object with the query string parameters added public static Url AddQueryParams(this string url, IDictionary values) { - return new Url(url).AddQueryParams(values); + return new Url(url).SetQueryParams(values); } /// diff --git a/Flurl/Url.cs b/Flurl/Url.cs index 439c558..5dff8b3 100644 --- a/Flurl/Url.cs +++ b/Flurl/Url.cs @@ -41,23 +41,24 @@ namespace Flurl /// Basically a Path.Combine for URLs. Ensures exactly one '/' character is used to seperate each segment. /// URL-encodes illegal characters but not reserved characters. /// - /// The URL to use as a starting point (required). NOT URL-encoded. + /// The URL to use as a starting point (required). /// Paths to combine. /// - public static string Combine(string baseUrl, params string[] segments) { - if (baseUrl == null) - throw new ArgumentNullException("baseUrl"); + public static string Combine(string url, params string[] segments) { + if (url == null) + throw new ArgumentNullException("url"); - return new Url(baseUrl).AppendPathSegments(segments).ToString(); + return new Url(url).AppendPathSegments(segments).ToString(); } /// - /// Encodes characters that are strictly illegal in a URL. Does not encode reserved characters, i.e. '/', '+', etc. + /// Encodes characters that are illegal in a URL path, including '?'. Does not encode reserved characters, i.e. '/', '+', etc. /// /// /// - public static string Cleanse(string url) { - return Uri.EscapeUriString(url); + private static string CleanSegment(string url) { + // http://stackoverflow.com/questions/4669692/valid-characters-for-directory-part-of-a-url-for-short-links + return HttpUtility.UrlPathEncode(url).Replace("?", "%3F"); } /// @@ -71,7 +72,7 @@ namespace Flurl throw new ArgumentNullException("segment"); if (!Path.EndsWith("/")) Path += "/"; - Path += HttpUtility.UrlPathEncode(segment.TrimStart('/').TrimEnd('/')); + Path += CleanSegment(segment).TrimStart('/').TrimEnd('/'); return this; } @@ -103,7 +104,7 @@ namespace Flurl /// name of query string parameter /// value of query string parameter /// The Url obect with the query string parameter added - public Url AddQueryParam(string name, object value) { + public Url SetQueryParam(string name, object value) { QueryParams[name] = (value == null) ? null : value.ToString(); return this; } @@ -113,12 +114,12 @@ namespace Flurl /// /// Typically an anonymous object, ie: new { x = 1, y = 2 } /// The Url object with the query string parameters added - public Url AddQueryParams(object values) { + public Url SetQueryParams(object values) { if (values == null) return this; foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(values)) - AddQueryParam(prop.Name, prop.GetValue(values)); + SetQueryParam(prop.Name, prop.GetValue(values)); return this; } @@ -128,12 +129,12 @@ namespace Flurl /// /// Dictionary of key/value pairs to add to the query string /// The Url object with the query string parameters added - public Url AddQueryParams(IDictionary values) { + public Url SetQueryParams(IDictionary values) { if (values == null) return this; foreach (var key in values.Keys) - AddQueryParam(key.ToString(), values[key]); + SetQueryParam(key.ToString(), values[key]); return this; }