Skip to content

Commit 8c6170e

Browse files
committed
Added: Support for HTML5 "form" attribute on form elements outside form tag.
1 parent 3308fdf commit 8c6170e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

WinHttp.au3

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,14 @@ 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+
$sHTML = StringReplace($sHTML, $sForm, ">")
12211222
Local $sSpr1 = Chr(27), $sSpr2 = Chr(26)
12221223
__WinHttpNormalizeForm($sForm, $sSpr1, $sSpr2)
12231224
$aInput = StringRegExp($sForm, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3)
1225+
; HTML5 "form" attribute on form elements
1226+
__WinHttpHTML5Form($sHTML, $sId, @error, $aInput)
12241227
If @error Then Return SetError(2, 0, "") ; invalid form
1228+
$sHTML = ""
12251229
; HTML5 allows for "formaction", "formenctype", "formmethod" submit-control attributes to be set. If such control is "clicked" then form's attributes needs updating/correcting
12261230
__WinHttpHTML5FormAttribs($aDtas, $aFlds, $iNumParams, $aInput, $sAction, $sEnctype, $sMethod)
12271231
; Workout correct URL, scheme, etc...
@@ -2103,6 +2107,23 @@ Func __WinHttpNormalizeActionURL($sActionPage, ByRef $sAction, ByRef $iScheme, B
21032107
If $sMethod = "GET" Then $sEnctype = ""
21042108
EndFunc
21052109

2110+
Func __WinHttpHTML5Form($sHTML, $sId, $iFormErr, ByRef $aInput)
2111+
If $sId Then
2112+
If $iFormErr Then Dim $aInput[1]
2113+
$aInputHTML5 = StringRegExp($sHTML, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3)
2114+
If Not @error Then
2115+
For $sElem In $aInputHTML5
2116+
If __WinHttpAttribVal($sElem, "form") = $sId Then
2117+
$iFormErr = 0
2118+
ReDim $aInput[UBound($aInput) + 1]
2119+
$aInput[UBound($aInput) - 1] = $sElem
2120+
EndIf
2121+
Next
2122+
EndIf
2123+
EndIf
2124+
Return SetError($iFormErr, 0, "")
2125+
EndFunc
2126+
21062127
Func __WinHttpHTML5FormAttribs(ByRef $aDtas, ByRef $aFlds, ByRef $iNumParams, ByRef $aInput, ByRef $sAction, ByRef $sEnctype, ByRef $sMethod)
21072128
; Clicking "submit" is done using:
21082129
; "type:submit", zero_based_index_of_the_submit_button

0 commit comments

Comments
 (0)