Skip to content

Commit e12e6c3

Browse files
AlirezaMaddahemmaworleyConnor Worleydependabot[bot]
authored
#193 Fix InvalidCastException (#197)
* #193 Fix InvalidCastException 1. Turn off DateTime parsing by JsonTextReader 2. Perform parsing in DateTimeDecoder using the same Culture and DateTimeKind. 3. Added tests to verify the behavior. * Initial attempt at building/testing/publishing under linux (#196) * Initial attempt at building/testing/publishing under linux * replace backslash with forwardslash * Attempt to add unit test coverage reports * try to fix gh actions syntax error * try to fix gh actions syntax error again * try to fix conditional expression for publishing coverage * try to fix conditional expression for publishing coverage again * only run CI on ubuntu * PR feedback * no multi-line run directives on windows Co-authored-by: Connor Worley <[email protected]> * Bump peter-evans/create-pull-request from v3.4.1 to v3.6.0 (#198) Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from v3.4.1 to v3.6.0. - [Release notes](https://github.com/peter-evans/create-pull-request/releases) - [Commits](peter-evans/create-pull-request@v3.4.1...45c510e) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/setup-python from v2.1.4 to v2.2.1 (#195) Bumps [actions/setup-python](https://github.com/actions/setup-python) from v2.1.4 to v2.2.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@v2.1.4...3105fb1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump codecov/codecov-action from v1.0.15 to v1.1.1 (#201) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from v1.0.15 to v1.1.1. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/master/CHANGELOG.md) - [Commits](codecov/codecov-action@v1.0.15...1fc7722) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * #193 Fix InvalidCastException 1. Turn off DateTime parsing by JsonTextReader 2. Perform parsing in DateTimeDecoder using the same Culture and DateTimeKind. 3. Added tests to verify the behavior. Co-authored-by: Connor Worley <[email protected]> Co-authored-by: Connor Worley <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 6cbeba5 commit e12e6c3

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

dropbox-sdk-dotnet/Dropbox.Api.Integration.Tests/DropboxApiTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,5 +476,38 @@ public async Task TestDropboxClientDispose()
476476
}
477477
Assert.IsTrue(canceled);
478478
}
479+
480+
/// <summary>
481+
/// Test upload with a date-time format file name.
482+
/// </summary>
483+
/// <returns></returns>
484+
[TestMethod]
485+
public async Task TestUploadWithDateName()
486+
{
487+
var fileNameWithDateFormat = DateTime.Now.ToString("s");
488+
var response = await Client.Files.UploadAsync($"{TestingPath}/{fileNameWithDateFormat}", body: GetStream("abc"));
489+
Assert.AreEqual(response.Name, fileNameWithDateFormat);
490+
Assert.AreEqual(response.PathLower, $"{TestingPath.ToLower()}/{fileNameWithDateFormat.ToLowerInvariant()}");
491+
Assert.AreEqual(response.PathDisplay, $"{TestingPath}/{fileNameWithDateFormat}");
492+
var downloadResponse = await Client.Files.DownloadAsync($"{TestingPath}/{fileNameWithDateFormat}");
493+
var content = await downloadResponse.GetContentAsStringAsync();
494+
Assert.AreEqual("abc", content);
495+
}
496+
497+
/// <summary>
498+
/// Test folder creation with a date-time format folder name.
499+
/// </summary>
500+
/// <returns></returns>
501+
[TestMethod]
502+
public async Task TestCreateFolderWithDateFormat()
503+
{
504+
var folderNameWithDateFormat = DateTime.Now.ToString("s");
505+
var response = await Client.Files.CreateFolderAsync($"{TestingPath}/{folderNameWithDateFormat}");
506+
Assert.AreEqual(response.Name, folderNameWithDateFormat);
507+
Assert.AreEqual(response.PathLower, $"{TestingPath.ToLower()}/{folderNameWithDateFormat.ToLowerInvariant()}");
508+
Assert.AreEqual(response.PathDisplay, $"{TestingPath}/{folderNameWithDateFormat}");
509+
var folders = await Client.Files.ListFolderAsync($"/{TestingPath}");
510+
Assert.IsTrue(folders.Entries.Any(f => f.Name == folderNameWithDateFormat));
511+
}
479512
}
480513
}

dropbox-sdk-dotnet/Dropbox.Api/Stone/Decoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ internal sealed class DateTimeDecoder : IDecoder<DateTime>
268268
/// <returns>The value.</returns>
269269
public DateTime Decode(IJsonReader reader)
270270
{
271-
return reader.ReadDateTime();
271+
return DateTime.Parse(reader.ReadString(), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
272272
}
273273
}
274274

dropbox-sdk-dotnet/Dropbox.Api/Stone/JsonReader.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ bool IJsonReader.IsNull
9090
/// <returns>The decoded object.</returns>
9191
public static T Read<T>(string json, IDecoder<T> decoder)
9292
{
93-
var reader = new JsonReader(new JsonTextReader(new StringReader(json)));
93+
var reader = new JsonReader(new JsonTextReader(new StringReader(json))
94+
{
95+
DateParseHandling = DateParseHandling.None
96+
});
9497
return decoder.Decode(reader);
9598
}
9699

0 commit comments

Comments
 (0)