Just discovered that in Adobe CF 2023, `.isEmpty()...
# adobe
n
Just discovered that in Adobe CF 2023,
.isEmpty()
on an empty string in a query result returns
NO
. It had returned
YES
in CF 2021 and CF 2018. I would expect it to return
YES
. It returns
YES
outside of a query result, for example, with a string or a string value in a struct. Is there a setting for this, or is it a bug? https://trycf.com/gist/0d6b615a9fb1783169826f69b86a7f57/acf2023?theme=monokai
s
Copy code
<cfscript>
    
news = queryNew(
    "id,title",
    "integer,varchar",
    [ {"id":1,"title":""} ]
);

writeDump(news.title[1].isEmpty());
    
</cfscript>
A slight change to your code, adding the explicit row index, and it returns
YES
as expected.
n
Good call. Is ACF 2023 less forgiving with implicit 1st row index? (I'd typically convert query results to a struct or array of structs, but this issue showed up in legacy code we'd need to cleanup all over the place if it's not going to be reliable.)
d
Gotta say, that's pretty weird, bug-like even. Is that an official change? We need to find everywhere our code references the first row of a query without explicitly providing the row index? Ugh.
m
@priyank_adobe should I drop this in a Jira?
s
I'm surprised it worked without looping over the query but, hey, CFML often surprises me by allowing me to do "dumb" things... 🙂
n
Created a bug: https://tracker.adobe.com/#/view/CF-4219387 I'd appreciate the upvotes... unless @Mark Takata (Adobe) can escalate quicker. 😄
c
I thought it was an official thing/feature/supposed to work that way that if you didn't specify a row a query should always return the first row.
4
r
Is isEmpty() an ACF BIF? I only see it in Lucee as a BIF.
n
Good point.
isEmpty()
the headless function is Lucee-only. I was referring to a string member function
someString.isEmpty()
. But now that I'm looking, technically this may be an undocumented feature. I don't see it in Adobe's docs. Only the
.isEmpty()
member function for
arrayIsEmpty()
and
structIsEmpty()
is documented. But, I've used it for years (since CF11 at least) to check if the value of a string variable is an empty string.
👍 1
h
I thought it was an official thing/feature/supposed to work that way that if you didn't specify a row a query should always return the first row.
Same, I have a ton of legacy code that does this.
d
CFDocs does say isEmpty() is Luceee only. Wouldn't it be the same for any other reference to columns in the query though?
But actually. the original code in this thread never returns on trycf Lucee5, but it does return on ACF 2018, 2019, and 2021, with a different nswer for 2021.
n
@Dave Merrill Yep, the headless function
isEmpty()
is Lucee only. But the member function
.isEmpty()
works in both. I think tryCF is having issues with Lucee5 at the moment, at least on my end. Nothing works. Happens occasionally on tryCF.
d
Plot thickens a bit. Of all the ACF engines on trycf, only 2018 and 2021 return YES for
news.title.isEmpty()
. All versions return YES for
news.title[1].isEmpty()
. All versions return the correct value for
news.title
and
news.title[1]
. Upshot is that the issue appears to be only with isEmpty(), not query column references with no row number in general. So yay.
👍 2
n
That's a good observation. Member function support wasn't fully baked in ACF till relatively recently... I'm not surprised that pre-2018,
news.title.isEmpty()
wasn't working as expected. But the issue remains that it regressed in 2023, as it was working in 2018 and 2021. Also, I haven't tested all valid member functions against fields in the implicitly referenced 1st row of a query result, so it's possible other member functions are affected as well.
👎 1
r
It's not a CF member function though. It's an undocumented feature.
2
d
Yeah, not in the ACF docs at all, so it's probably accidentally poking up from Java. As to how bogus it its that it behaves differently in different versions of ACF, much as I wish otherwise, meh. We don't really get to complain about changes to the behavior of undocumented features, methinks.
n
.isEmpty()
is a Java function in the
String
class, so you may be spot on. Considering it works on strings in CF, maybe the problem is not that it should work as a native CF method, but that CF is incorrectly data-typing
news.title
when the row number is unspecified.
1
d
I'm just super happy that the implicit-first-row-if-not-specified behavior when referencing query values hasn't changed. That would have needed some nasty rework in many hard-to-search-for places.
💯 1
n
https://trycf.com/gist/5dbfea16154e2b8bda525204d618f4bf/acf2023?theme=monokai Some variations... Both alternatives return "YES" in ACF 2023
d
It's hard to understand how isEmpty() could be wrong if references to the value are right. But I'm past the point where I care a ton frankly. I can ask for the value, as in all prior and current versions, and I can check its length, and check if it's equal to empty string, so nothing has changed on that level, so I'm good. We weren't using that undocumented function, as I'd expect us not to do 🙂