Lucee, you're a bad girl!!! ```<cfoutput>#is...
# lucee
e
Lucee, you're a bad girl!!!
Copy code
<cfoutput>#isValid("integer", "no")#</cfoutput>
https://trycf.com/gist/83faa53bd3a1eb9e66eb66e6d89c7a51/lucee5?theme=monokai
z
and it's not a acf compat quirk either
related (for "yes") LDEV-2642
here's the ticket for that problem https://luceeserver.atlassian.net/browse/LDEV-3767
fixed in 6.0 tho
👍 2
🙌 1
e
Good girl 🤣
z
when did trycf add 6 beta?
e
Didn't see that before.
a
Uncharacteristically for me, I'm actually with Lucee 5 on this one.
"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)
Copy code
<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>
Copy code
true
0
true
-1
-1
e
Lucee seems to converty "no|yes" to 0/1 in most cases, but not in the queryparam. This was my use case:
Copy code
var 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.
Copy code
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.
Could inline the Long stuff:
createObject("java", "java.lang.Long").parseLong(s)
@bdw429s does
cbValidation
work as a stand-alone lib, or does it have CB dependencies baked into it? (ref for @eyk https://coldbox-validation.ortusbooks.com/)
I'd use a proper third-party lib for validating incoming request values though. Not hand-crank my own.
cb libs tend to have framework deps baked into them though, unfortunately. So not as portable as they could be.
f
so your telling me
"yes" > "no"
😆
😄 3
b
I'm fairly sure cbvalidation needs ColdBox. That said, it uses
isValid()
for a lot of things under the hood.
👍 1
z
isValid is often as quirky as the electoral college
e
Maybe the german electoral college..
z
the one the allies designed/.