Skip to content

Commit d25e791

Browse files
committed
Use region invariant date for UrlEncoded
1 parent 0329bcb commit d25e791

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

specs/Specs_WebHelpers.bas

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Public Function Specs() As SpecSuite
2929
Dim XmlString As String
3030
Dim Parsed As Object
3131
Dim Obj As Object
32+
Dim LocalDate As Date
3233
Dim Coll As Collection
3334
Dim Bytes() As Byte
3435
Dim Str As String
@@ -142,12 +143,25 @@ Public Function Specs() As SpecSuite
142143
Set Obj = New Dictionary
143144

144145
Obj.Add "a", 1
145-
Obj.Add "b", 3.14
146-
Obj.Add "c", "Howdy!"
147-
Obj.Add "d & e", "A + B"
146+
Obj.Add "b", "Howdy!"
147+
Obj.Add "c & d", "A + B"
148148

149149
Encoded = WebHelpers.ConvertToUrlEncoded(Obj)
150-
.Expect(Encoded).ToEqual "a=1&b=3.14&c=Howdy!&d+%26+e=A+%2B+B"
150+
.Expect(Encoded).ToEqual "a=1&b=Howdy!&c+%26+d=A+%2B+B"
151+
End With
152+
153+
With Specs.It("should use region invariant numbers and dates")
154+
Set Obj = New Dictionary
155+
LocalDate = 38113.7973263889
156+
157+
Obj.Add "a", 1000.123
158+
Obj.Add "b", LocalDate
159+
160+
Encoded = WebHelpers.ConvertToUrlEncoded(Obj)
161+
162+
' Don't test hour/minute due to UTC offset
163+
.Expect(Encoded).ToMatch "a=1000.123&b=2004-05-06T"
164+
.Expect(Encoded).ToMatch "%3A09.000Z"
151165
End With
152166

153167
' ParseXml

src/WebHelpers.bas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,9 @@ Private Function web_GetUrlEncodedKeyValue(Key As Variant, Value As Variant) As
17441744
Else
17451745
Value = "false"
17461746
End If
1747+
Case VBA.vbDate
1748+
' Use region invariant date (ISO-8601)
1749+
Value = WebHelpers.ConvertToIso(CDate(Value))
17471750
Case VBA.vbDecimal, VBA.vbSingle, VBA.vbDouble, VBA.vbCurrency
17481751
' Use region invariant number encoding ("." for decimal separator)
17491752
Value = VBA.Replace(VBA.CStr(Value), ",", ".")

0 commit comments

Comments
 (0)