-
Notifications
You must be signed in to change notification settings - Fork 23
issue in _WD_ExecuteScript / __WD_EscapeString when comments // was used in JavaScript string #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
interesting. _Example()
Func _Example()
Local $sJavaScript = _
"// comment" & @CRLF & _
"return document.readyState;" & @CRLF & _
""
_WD_DebugSwitch($_WD_DEBUG_Full)
_WD_ExecuteScript($sSession, $sJavaScript)
_WD_DebugSwitch()
EndFunc ;==>_Example I get proper results:
the same result with: _Example()
Func _Example()
Local $sJavaScript = _
"// comment" & @CR & _
"return document.readyState;" & @CR & _
""
_WD_DebugSwitch($_WD_DEBUG_Full)
_WD_ExecuteScript($sSession, $sJavaScript)
_WD_DebugSwitch()
EndFunc ;==>_Example and with: _Example()
Func _Example()
Local $sJavaScript = _
"// comment" & @LF & _
"return document.readyState;" & @LF & _
""
_WD_DebugSwitch($_WD_DEBUG_Full)
_WD_ExecuteScript($sSession, $sJavaScript)
_WD_DebugSwitch()
EndFunc ;==>_Example |
Not me. I got this --
Edit: Notice the difference in the Data portion of mine VS yours. Are you sure you are testing with the latest release? |
oops.. my mistake. I had little modified verison because I was testing this issue. my results are:
the issue can be solved by: Func __WD_EscapeString($sData, $iOption = 0)
If BitAND($iOption, $JSON_MLREFORMAT) Then
;~ $sData = StringRegExpReplace($sData, '[\v\t]', '') ; Strip tabs and CR/LFs ; original
$sData = StringRegExpReplace($sData, '\t', '') ; Strip tabs ; modified and results are:
|
we should re-test: |
from: #465 ConsoleWrite("! Start: UserTesting_EscapeString.au3" & @CRLF)
ConsoleWrite("- Test 1:" & @CRLF)
_WD_Navigate($sSession, 'https://www.google.com')
_WD_LoadWait($sSession)
MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONWARNING, "Warning #" & @ScriptLineNumber, "If you see COOKIE accept panel close them before you will continue.")
ConsoleWrite("- Test 2:" & @CRLF)
; REMARK: __SetVAR($IDX_VAR, $value) will set $_VAR[$IDX_VAR] = $value
__SetVAR(0, _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//textarea[@name='q']"))
ConsoleWrite("- Test 3:" & @CRLF)
__SetVAR(1, ' " ! @ # $ % ^ & * ( ) - _ + = { } [ ] ; : \ | , . < > / ? ~ ' & " ' " & ' @CR' & @CR & ' @CRLF' & @CRLF & ' @LF' & @LF & ' @TAB' & @TAB & 'END')
_WD_ElementAction($sSession, $_VAR[0], "VALUE", $_VAR[1])
;~ _WD_SetElementValue($sSession, $_VAR[0], $_VAR[1], $_WD_OPTION_Advanced)
ConsoleWrite("! $_VAR[1] -" & @CRLF & $_VAR[1] & @CRLF)
ConsoleWrite("! __WD_EscapeString($_VAR[0]) -" & @CRLF & __WD_EscapeString($_VAR[1]) & @CRLF)
ConsoleWrite("! END: UserTesting_EscapeString.au3" & @CRLF) together with current modification: Func __WD_EscapeString($sData, $iOption = 0)
If BitAND($iOption, $JSON_MLREFORMAT) Then
;~ $sData = StringRegExpReplace($sData, '[\v\t]', '') ; Strip tabs and CR/LFs ; original
$sData = StringRegExpReplace($sData, '\t', '') ; Strip tabs ; modified I get:
for me the following fix Func __WD_EscapeString($sData, $iOption = 0)
If BitAND($iOption, $JSON_MLREFORMAT) Then
;~ $sData = StringRegExpReplace($sData, '[\v\t]', '') ; Strip tabs and CR/LFs ; original
$sData = StringRegExpReplace($sData, '\t', '') ; Strip tabs ; modified works fine. |
|
@Danp2 If you agree with my testing route and results, I pass the solution of this problem to you (please make PR). |
btw. results - works fine. |
Yes, I think it is important to understand why the original change was made before reverting so that we can hopefully avoid creating a different issue. |
I think this was my mistake. |
quick review and I think it starts here: |
finall fix proposal: ; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WD_EscapeString
; Description ...: Escapes designated characters in string.
; Syntax ........: __WD_EscapeString($sData[, $iOption = 0])
; Parameters ....: $sData - the string to be escaped
; $iOption - [optional] Any combination of $JSON_* constants. Default is 0.
; Author ........: Danp2, mLipok
; Modified ......:
; Remarks .......: $JSON_MLREFORMAT will strip tabs from a multiline string (ie. indentation) as they are not supported by WebDriver, use \t where it is needed
; See $JSON_* constants in json.au3 for other $iOption possibilities.
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WD_EscapeString($sData, $iOption = 0)
If BitAND($iOption, $JSON_MLREFORMAT) Then
$sData = StringRegExpReplace($sData, '\t', '') ; Strip tabs
$iOption = BitXOR($iOption, $JSON_MLREFORMAT) ; Flip bit off
EndIf
$sData = Json_StringEncode($sData, $iOption) ; Escape JSON Strings
Return SetError($_WD_ERROR_Success, 0, $sData)
EndFunc ;==>__WD_EscapeString |
An alternative is to drop the use of $JSON_MLREFORMAT in _WD_ExecuteScript, but still awaiting your clarification here. |
* _WD_ElementSelectAction 'selectedOptions' group (#375) * _WD_ElementSelectAction 'options' added group name (#374) * _WD_ElementSelectAction 'selectAll' JS validation (#373) * _WD_ElementSelectAction 'selectedLabels' JS refact (#376) * _WD_ElementSelectAction + SINGLESELECT (#367) * _ElementSelectAction : JS refactoring + case insensivity (#381) * Return result from `selectAll` * selectAll + $_WD_ERROR_NoMatch
take a look here: from this time my experience says to mee each time I use TABS in Line 2276 in 5bb7a7a
|
I will do test today to clarify if TABS are allowed or not. |
If your results match mine, then I would suggest that we drop the usage of $JSON_MLREFORMAT |
So please do this test:
this should explain why I said that TABS used directly in my results are:
|
last post edited (sorry for the confusion) |
oops. |
I think the simplest way to perform this testing is to change the following line in _WD_ExecuteScript --
to
Then test all JS functionality to see if there are any negative effects. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
After some more testing I think this should be fine. I think that here: Lines 1690 to 1699 in 81154ab
this following part was bad as it was no taking all cases: Local $sRegEx = "([" & $_WD_ESCAPE_CHARS & "])" and thus I wanted to add: $sData = StringRegExpReplace($sData, '[\v\t]', '') ; Strip tabs and CR/LFs but you propose to use: $sData = Json_StringEncode($sData, $iOption) ; Escape JSON Strings your proposal was covering also my request about fixing Lines 1691 to 1694 in 81154ab
|
|
Bug report
Describe the bug
$sData = StringRegExpReplace($sData, '[\v\t]', '')
from here:
au3WebDriver/wd_core.au3
Lines 1747 to 1749 in 42dda7d
strips
[\v]
chars and when// comment
is used entire$sJavaScript
becames commented out.How to reproduce
Expected behavior
get result from:
return document.readyState;
Screenshots
none
Additional context
https://www.autoitscript.com/forum/topic/208640-webdriver-udf-help-support-iv/?do=findComment&comment=1521863
System under test
not related
The text was updated successfully, but these errors were encountered: