@@ -678,7 +678,7 @@ End Sub
678
678
''
679
679
Public Sub AddCookie (Key As String , Value As Variant )
680
680
Me.Cookies.Add WebHelpers.CreateKeyValue( _
681
- Key, _
681
+ web_EncodeCookieName( Key) , _
682
682
WebHelpers.UrlEncode(Value, EncodingMode:=UrlEncodingMode.CookieUrlEncoding) _
683
683
)
684
684
End Sub
@@ -810,6 +810,55 @@ End Sub
810
810
' Private Functions
811
811
' ============================================= '
812
812
813
+ ' Encode cookie name
814
+ '
815
+ ' References:
816
+ ' - RFC 6265 https://tools.ietf.org/html/rfc6265
817
+ Private Function web_EncodeCookieName (web_CookieName As Variant ) As String
818
+ Dim web_CookieVal As String
819
+ Dim web_StringLen As Long
820
+
821
+ web_CookieVal = VBA.CStr(web_CookieName)
822
+ web_StringLen = VBA.Len(web_CookieVal)
823
+
824
+ If web_StringLen > 0 Then
825
+ Dim web_Result() As String
826
+ Dim web_i As Long
827
+ Dim web_CharCode As Integer
828
+ Dim web_Char As String
829
+ ReDim web_Result(web_StringLen)
830
+
831
+ ' ALPHA / DIGIT / "!" / "#" / "$" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
832
+ ' Note: "%" is allowed in spec, but is currently excluded due to parsing issues
833
+
834
+ ' Loop through string characters
835
+ For web_i = 1 To web_StringLen
836
+ ' Get character and ascii code
837
+ web_Char = VBA.Mid$(web_CookieVal, web_i, 1 )
838
+ web_CharCode = VBA.Asc(web_Char)
839
+
840
+ Select Case web_CharCode
841
+ Case 65 To 90 , 97 To 122
842
+ ' ALPHA
843
+ web_Result(web_i) = web_Char
844
+ Case 48 To 57
845
+ ' DIGIT
846
+ web_Result(web_i) = web_Char
847
+ Case 33 , 35 , 36 , 38 , 39 , 42 , 43 , 45 , 46 , 94 , 95 , 96 , 124 , 126
848
+ ' "!" / "#" / "$" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
849
+ web_Result(web_i) = web_Char
850
+
851
+ Case 0 To 15
852
+ web_Result(web_i) = "%0" & VBA.Hex(web_CharCode)
853
+ Case Else
854
+ web_Result(web_i) = "%" & VBA.Hex(web_CharCode)
855
+ End Select
856
+ Next web_i
857
+
858
+ web_EncodeCookieName = VBA.Join$(web_Result, "" )
859
+ End If
860
+ End Function
861
+
813
862
Private Sub Class_Initialize ()
814
863
' Set default values
815
864
Me.RequestFormat = WebFormat.Json
0 commit comments