Skip to content

Commit

Permalink
Merge pull request #114 from turenkomv/feature/PREF-2510
Browse files Browse the repository at this point in the history
[PREF-2510] Escape '+' char in time zone
  • Loading branch information
ZEXSM authored May 19, 2023
2 parents 7d9f7fb + 3e9101b commit 64ca0b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/OData.QueryBuilder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public static IEnumerable<string> ReplaceWithStringBuilder(this ICollection<stri
bool @bool => @bool ? "true" : "false",
DateTime dateTime => options switch
{
{ UseCorrectDateTimeFormat: true } => $"{dateTime:yyyy-MM-ddTHH:mm:sszzz}",
{ UseCorrectDateTimeFormat: true } =>
$"{dateTime:yyyy-MM-ddTHH:mm:sszzz}".Replace("+", "%2B"),
_ => $"{dateTime:s}Z"
},
DateTimeOffset dateTimeOffset => options switch
{
{ UseCorrectDateTimeFormat: true } => $"{dateTimeOffset:yyyy-MM-ddTHH:mm:sszzz}",
{ UseCorrectDateTimeFormat: true } =>
$"{dateTimeOffset:yyyy-MM-ddTHH:mm:sszzz}".Replace("+", "%2B"),
_ => $"{dateTimeOffset:s}Z"
},
string @string => $"'{@string}'",
Expand Down
15 changes: 10 additions & 5 deletions test/OData.QueryBuilder.Test/ODataQueryCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,21 +1574,26 @@ public void ODataQueryBuilderList_UseCorrectDatetimeFormat_Convert_Success()
var dateTimeUtc = new DateTime(
year: 2023, month: 04, day: 07, hour: 12, minute: 30, second: 20, kind: DateTimeKind.Utc);
var dateTimeOffset = new DateTimeOffset(
year: 2023, month: 04, day: 07, hour: 12, minute: 30, second: 20, offset: TimeSpan.FromHours(+7));
year: 2023, month: 04, day: 07, hour: 12, minute: 30, second: 20, offset: TimeSpan.FromHours(+7));
var dateTimeOffset2 = new DateTimeOffset(
year: 2023, month: 04, day: 07, hour: 12, minute: 30, second: 20, offset: TimeSpan.FromHours(-7));
var nowOffset = $"{DateTimeOffset.Now:zzz}".Replace("+", "%2B");

var uri = builder
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Filter((o) =>
o.DateTime == dateTimeLocal
&& o.DateTime == dateTimeUtc
&& o.DateTime == dateTimeOffset)
&& o.DateTime == dateTimeOffset
&& o.DateTime == dateTimeOffset2)
.ToUri();

uri.Should().Be($"http://mock/odata/ODataType?$filter=" +
$"DateTime eq 2023-04-07T12:30:20{DateTimeOffset.Now:zzz} and " +
$"DateTime eq 2023-04-07T12:30:20+00:00 and " +
$"DateTime eq 2023-04-07T12:30:20+07:00");
$"DateTime eq 2023-04-07T12:30:20{nowOffset} and " +
$"DateTime eq 2023-04-07T12:30:20%2B00:00 and " +
$"DateTime eq 2023-04-07T12:30:20%2B07:00 and " +
$"DateTime eq 2023-04-07T12:30:20-07:00");
}
}
}

0 comments on commit 64ca0b8

Please sign in to comment.