View Full Version : Odd JScript behaviour
pjaquiery
01-23-2006, 06:27 PM
If I use
["/samplestring/".replace (/[[\\\/]]$/, "")]
as the Value: for a Set Macro step the macro is set to
/samplestring/
and is also shown in the mouseover tool tip with shift down. If I use the immediate pane in the Script Editor to evaluate:
"/samplestring/".replace (/[\\\/]$/, "")
I get:
/samplestring
What am I missing here?
Update: replace (/(\\|\/)$/, "") works around the problem
kinook
01-24-2006, 11:39 AM
The first result is due to how macros and script are processed in a field values (see http://www.kinook.com/Forum/showthread.php?threadid=1383). When evaluated (in the build or with Shift down over a field), the by-design behavior applies to the expression containing nested literals [[...]].
But when code is evaluated in the Immediate window, this extra processing is not performed (the value entered is treated as the script code to evaluate and no additional processing of nested script expressions or literal [[ ]] is performed).
pjaquiery
01-24-2006, 02:46 PM
I keep getting bitten by this don't I? :)
Is it possible (and sensible) to detect the context where this happens and generate a warning?
kinook
01-24-2006, 03:52 PM
There's no easy way to do that without potentially breaking other existing projects. It is doing the wrong thing in your situation, but it's possible for the result to be correct in other scenarios. For compatibility, the evaluation still needs to return the value it currently does (and not an error message instead). You could run all your .bld files through the attached project to identify problem field values (I apologize for using *spit* VBScript for the sample :^).
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.