Skip to content

Commit 68e2e7e

Browse files
committed
Fix bugs caused by unicode characters in Dropbox-API-Args header
1 parent 71c9199 commit 68e2e7e

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

Dropbox.Api/Babel/IEncodable.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

Dropbox.Api/Babel/JsonWriter.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ private JsonWriter(JsonTextWriter writer)
3939
/// <param name="encodable">The object to write.</param>
4040
/// <param name="encoder">The encoder.</param>
4141
/// <returns>The encoded object as a JSON string.</returns>
42-
public static string Write<T>(T encodable, IEncoder<T> encoder)
42+
public static string Write<T>(T encodable, IEncoder<T> encoder, bool escapeNonAscii = false)
4343
{
4444
var builder = new StringBuilder();
45-
var writer = new JsonWriter(new JsonTextWriter(new StringWriter(builder)));
45+
var textWriter = new JsonTextWriter(new StringWriter(builder));
46+
47+
if (escapeNonAscii)
48+
{
49+
textWriter.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;
50+
}
51+
52+
var writer = new JsonWriter(textWriter);
4653
encoder.Encode(encodable, writer);
4754

4855
var json = builder.ToString();

Dropbox.Api/Dropbox.Api.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>$id$</id>
5-
<version>2.0.2</version>
5+
<version>2.0.3</version>
66
<title>Dropbox v2 API Beta</title>
77
<authors>Dropbox Inc</authors>
88
<owners>Dropbox Inc</owners>

Dropbox.Api/DropboxRequestHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ async Task<TResponse> ITransport.SendUploadRequestAsync<TRequest, TResponse, TEr
156156
IDecoder<TResponse> resposneDecoder,
157157
IDecoder<TError> errorDecoder)
158158
{
159-
var serializedArg = JsonWriter.Write(request, requestEncoder);
159+
var serializedArg = JsonWriter.Write(request, requestEncoder, true);
160160
var res = await this.RequestJsonStringWithRetry(host, route, RouteStyle.Upload, serializedArg, body);
161-
161+
162162
if (res.IsError)
163163
{
164164
throw ApiException<TError>.Decode(res.ObjectResult, errorDecoder);

0 commit comments

Comments
 (0)