Skip to content

Commit

Permalink
#193 Fix InvalidCastException (#197)
Browse files Browse the repository at this point in the history
* #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 <cworley@dropbox.com>

* 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] <support@github.com>

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] <support@github.com>

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] <support@github.com>

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 <connorbworley@gmail.com>
Co-authored-by: Connor Worley <cworley@dropbox.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 4, 2021
1 parent 6cbeba5 commit e12e6c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,38 @@ public async Task TestDropboxClientDispose()
}
Assert.IsTrue(canceled);
}

/// <summary>
/// Test upload with a date-time format file name.
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task TestUploadWithDateName()
{
var fileNameWithDateFormat = DateTime.Now.ToString("s");
var response = await Client.Files.UploadAsync($"{TestingPath}/{fileNameWithDateFormat}", body: GetStream("abc"));
Assert.AreEqual(response.Name, fileNameWithDateFormat);
Assert.AreEqual(response.PathLower, $"{TestingPath.ToLower()}/{fileNameWithDateFormat.ToLowerInvariant()}");
Assert.AreEqual(response.PathDisplay, $"{TestingPath}/{fileNameWithDateFormat}");
var downloadResponse = await Client.Files.DownloadAsync($"{TestingPath}/{fileNameWithDateFormat}");
var content = await downloadResponse.GetContentAsStringAsync();
Assert.AreEqual("abc", content);
}

/// <summary>
/// Test folder creation with a date-time format folder name.
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task TestCreateFolderWithDateFormat()
{
var folderNameWithDateFormat = DateTime.Now.ToString("s");
var response = await Client.Files.CreateFolderAsync($"{TestingPath}/{folderNameWithDateFormat}");
Assert.AreEqual(response.Name, folderNameWithDateFormat);
Assert.AreEqual(response.PathLower, $"{TestingPath.ToLower()}/{folderNameWithDateFormat.ToLowerInvariant()}");
Assert.AreEqual(response.PathDisplay, $"{TestingPath}/{folderNameWithDateFormat}");
var folders = await Client.Files.ListFolderAsync($"/{TestingPath}");
Assert.IsTrue(folders.Entries.Any(f => f.Name == folderNameWithDateFormat));
}
}
}
2 changes: 1 addition & 1 deletion dropbox-sdk-dotnet/Dropbox.Api/Stone/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal sealed class DateTimeDecoder : IDecoder<DateTime>
/// <returns>The value.</returns>
public DateTime Decode(IJsonReader reader)
{
return reader.ReadDateTime();
return DateTime.Parse(reader.ReadString(), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
}
}

Expand Down
5 changes: 4 additions & 1 deletion dropbox-sdk-dotnet/Dropbox.Api/Stone/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ bool IJsonReader.IsNull
/// <returns>The decoded object.</returns>
public static T Read<T>(string json, IDecoder<T> decoder)
{
var reader = new JsonReader(new JsonTextReader(new StringReader(json)));
var reader = new JsonReader(new JsonTextReader(new StringReader(json))
{
DateParseHandling = DateParseHandling.None
});
return decoder.Decode(reader);
}

Expand Down

0 comments on commit e12e6c3

Please sign in to comment.