Skip to content

Commit a80f9bd

Browse files
committed
Added: Internal __WinHttpNormalizeForm.
1 parent 7e7be84 commit a80f9bd

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

WinHttp.au3

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,8 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
12181218
$sMethod = __WinHttpAttribVal($sAttributes, "method")
12191219
; Requested form is found. Set $fSend flag to true
12201220
$fSend = True
1221+
Local $sSpr1 = Chr(27), $sSpr2 = Chr(26)
1222+
__WinHttpNormalizeForm($sForm, $sSpr1, $sSpr2)
12211223
$aInput = StringRegExp($sForm, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3)
12221224
If @error Then Return SetError(2, 0, "") ; invalid form
12231225
; HTML5 allows for "formaction", "formenctype", "formmethod" submit-control attributes to be set. If such control is "clicked" then form's attributes needs updating/correcting
@@ -1233,8 +1235,8 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
12331235
For $i = 0 To UBound($aInput) - 1 ; for all input elements
12341236
__WinHttpFormAttrib($aInputIds, $i, $aInput[$i])
12351237
If $aInputIds[1][$i] Then ; if there is 'name' field then add it
1236-
$aInputIds[1][$i] = __WinHttpURLEncode($aInputIds[1][$i], $sEnctype)
1237-
$aInputIds[2][$i] = __WinHttpURLEncode($aInputIds[2][$i], $sEnctype)
1238+
$aInputIds[1][$i] = __WinHttpURLEncode(StringReplace($aInputIds[1][$i], $sSpr1, " "), $sEnctype)
1239+
$aInputIds[2][$i] = __WinHttpURLEncode(StringReplace(StringReplace($aInputIds[2][$i], $sSpr2, ">"), $sSpr1, " "), $sEnctype)
12381240
$sAddData &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & "&"
12391241
If $aInputIds[3][$i] = "submit" Then $sSubmit &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "submit" string
12401242
If $aInputIds[3][$i] = "radio" Then $sRadio &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "radio" string
@@ -1373,6 +1375,8 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
13731375
For $i = 0 To UBound($aInput) - 1 ; for all input elements
13741376
__WinHttpFormAttrib($aInputIds, $i, $aInput[$i])
13751377
If $aInputIds[1][$i] Then ; if there is 'name' field
1378+
$aInputIds[1][$i] = StringReplace($aInputIds[1][$i], $sSpr1, " ")
1379+
$aInputIds[2][$i] = StringReplace(StringReplace($aInputIds[2][$i], $sSpr2, ">"), $sSpr1, " ")
13761380
If $aInputIds[3][$i] = "file" Then
13771381
$sAddData &= "--" & $sBoundary & @CRLF & _
13781382
$sCDisp & $aInputIds[1][$i] & '"; filename=""' & @CRLF & @CRLF & _
@@ -2214,6 +2218,34 @@ Func __WinHttpHTML5FormAttribs(ByRef $aDtas, ByRef $aFlds, ByRef $iNumParams, By
22142218
EndIf
22152219
EndFunc
22162220

2221+
Func __WinHttpNormalizeForm(ByRef $sForm, $sSpr1, $sSpr2)
2222+
Local $aData = StringToASCIIArray($sForm, Default, Default, 2)
2223+
Local $sOut, $bQuot = False, $bSQuot = False
2224+
For $i = 0 To UBound($aData) - 1
2225+
Switch $aData[$i]
2226+
Case 34
2227+
$bQuot = Not $bQuot
2228+
Case 39
2229+
$bSQuot = Not $bSQuot
2230+
Case 32 ; space
2231+
If $bQuot Or $bSQuot Then
2232+
$sOut &= $sSpr1
2233+
Else
2234+
$sOut &= Chr($aData[$i])
2235+
EndIf
2236+
Case 62 ; >
2237+
If $bQuot Or $bSQuot Then
2238+
$sOut &= $sSpr2
2239+
Else
2240+
$sOut &= Chr($aData[$i])
2241+
EndIf
2242+
Case Else
2243+
$sOut &= Chr($aData[$i])
2244+
EndSwitch
2245+
Next
2246+
$sForm = $sOut
2247+
EndFunc
2248+
22172249
Func __WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, ByRef $sAddData, $sGrSep, $sBound = "")
22182250
If $sSubmit Then ; If no submit is specified
22192251
Local $aSubmit = StringSplit($sSubmit, $sGrSep, 3)

0 commit comments

Comments
 (0)