Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed special character encoding for Dropbox path in request url [SPR…

…NETSOCIALDB-5]
  • Loading branch information...
commit 191764578f55b3016dcc2c15850b367c67111095 1 parent 4e5eb4c
Bruno Baia bbaia authored
24 src/Spring.Social.Dropbox/Social/Dropbox/Api/Impl/DropboxTemplate.cs
View
@@ -1424,8 +1424,9 @@ private string BuildUrl(string path, string dropboxPath)
private string BuildUrl(string path, string dropboxPath, NameValueCollection parameters)
{
- string encodedDropboxPath = HttpUtils.UrlEncode(dropboxPath.TrimStart('/')).Replace("%2F", "/");
- return BuildUrl(path.TrimEnd('/') + "/" + this.root + "/" + encodedDropboxPath, parameters);
+ return BuildUrl(
+ path.TrimEnd('/') + "/" + this.root + "/" + DropboxPathEncode(dropboxPath.TrimStart('/')),
+ parameters);
}
private static string BuildUrl(string path, NameValueCollection parameters)
@@ -1450,6 +1451,25 @@ private static string BuildUrl(string path, NameValueCollection parameters)
return path + qsBuilder.ToString();
}
+ private const string DROPBOX_PATH_UNRESERVED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./";
+
+ private static string DropboxPathEncode(string path)
+ {
+ StringBuilder result = new StringBuilder();
+ foreach (char symbol in path)
+ {
+ if (DROPBOX_PATH_UNRESERVED_CHARS.IndexOf(symbol) != -1)
+ {
+ result.Append(symbol);
+ }
+ else
+ {
+ result.Append('%' + String.Format("{0:X2}", (int)symbol));
+ }
+ }
+ return result.ToString();
+ }
+
private static string ThumbnailSizeToString(ThumbnailSize size)
{
switch(size)
16 test/Spring.Social.Dropbox.Tests/Social/Dropbox/Api/Impl/DropboxTemplateTests.cs
View
@@ -576,6 +576,22 @@ public void DownloadThumbnailAndMetadata()
Assert.IsNull(thumbnail.Metadata.Contents);
}
+ [Test]
+ public void DropboxPathSpecialCharacters()
+ {
+ mockServer.ExpectNewRequest()
+ .AndExpectUri("https://api.dropbox.com/1/metadata/dropbox/%24%26%2B%2C%3B%3D%40%23%7B%7D%5E%7E%5B%5D%60%27%25%28%29%21-_/Spring%20Social.txt?list=false")
+ .AndExpectMethod(HttpMethod.GET);
+
+ MetadataParameters parameters = new MetadataParameters();
+ parameters.IncludeContents = false;
+#if NET_4_0 || SILVERLIGHT_5
+ dropbox.GetMetadataAsync("$&+,;=@#{}^~[]`'%()!-_/Spring Social.txt", parameters).Wait();
+#else
+ dropbox.GetMetadata("$&+,;=@#{}^~[]`'%()!-_/Spring Social.txt", parameters);
+#endif
+ }
+
// tests helpers
Please sign in to comment.
Something went wrong with that request. Please try again.