eyk
04/13/2023, 10:31 AM<cfoutput>#isValid("integer", "no")#</cfoutput>
https://trycf.com/gist/83faa53bd3a1eb9e66eb66e6d89c7a51/lucee5?theme=monokaizackster
04/13/2023, 11:10 AMzackster
04/13/2023, 11:11 AMzackster
04/13/2023, 11:12 AMzackster
04/13/2023, 11:13 AMeyk
04/13/2023, 11:13 AMzackster
04/13/2023, 11:14 AMeyk
04/13/2023, 11:16 AMAdam Cameron
"No" can and will be coerced into an integer when necessary.
And - as well all know after the seemingly-weekly "I don't understand CFML's type system" conversations here about why isValid can return unexpected results because it needs to be considered as a canBeUsedAs - "No" can be used anywhere in CFML that will coerce types, and the target type is an integer.
So isValid("integer", "no") should be "Yes" (sic)Adam Cameron
Adam Cameron
<cfoutput>#isValid("integer", "no")#</cfoutput>
<br>
<cfset i = "no" + "no">
<cfoutput>#i#</cfoutput>
<br>
<cfoutput>#isValid("integer", i)#</cfoutput>
<br>
<cfset i2 = decrementValue("No")>
<cfoutput>#i2#</cfoutput>
<br>
<cfset i3 = bitNot("No")>
<cfoutput>#i3#</cfoutput>
<br>
true
0
true
-1
-1eyk
04/13/2023, 2:02 PMvar id = URL.id ?: "no"
if(isValid("integer", URL.id)){
db("select 1 from images where pkimages = ? ", [{value:URL.id, cfsqltype:"integer"}])
I got an error there. But it would by pretty ugly if this would result in: where pkimages = 0 , if queryparam would convert "no" no 0.Adam Cameron
function isInteger(required string s) {
try {
var Long = createObject("java", "java.lang.Long")
Long.parseLong(s)
return true
} catch (any e) {
return false
}
}
Not very complicated to get what you need "properly" without coding in exceptions for strings like "No" etc.Adam Cameron
createObject("java", "java.lang.Long").parseLong(s)Adam Cameron
cbValidation work as a stand-alone lib, or does it have CB dependencies baked into it?
(ref for @eyk https://coldbox-validation.ortusbooks.com/)Adam Cameron
Adam Cameron
foundeo
"yes" > "no" 😆bdw429s
04/13/2023, 2:17 PMisValid() for a lot of things under the hood.zackster
04/13/2023, 2:49 PMEvil Ware
04/13/2023, 3:07 PMzackster
04/13/2023, 4:02 PM