Page MenuHomePhabricator

Phabricator global search: "Cannot use object of type PhutilSafeHTML as array" error for certain strings
Open, Needs TriagePublic

Description

When searching for certain strings in Phabricator there is an exception:

Unhandled Exception ("Error")
Cannot use object of type PhutilSafeHTML as array

Interestingly there are a few patterns that seem to trigger it while others don't. For example:

stringresult
foook
mw1234ok
mw2234error
mw222ok
mw2222error
xx2234ok
xxmw2234ok
mw2234xok
mw2261error
mw2261xok
cloudvirt1001error

The ones that are errors are repeatable and don't seem random. It seems more like the error happens if it actually finds some results?

Event Timeline

Dzahn created this task.Sep 16 2020, 9:21 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 16 2020, 9:21 PM
Aklapper renamed this task from Phabricator search - Cannot use object of type PhutilSafeHTML as array to Phabricator global search: "Cannot use object of type PhutilSafeHTML as array" error for certain strings.Sep 17 2020, 1:23 PM
greg updated the task description. (Show Details)Sep 17 2020, 4:13 PM
greg added a subscriber: greg.Sep 17 2020, 4:19 PM

Luckily searching for "Cannot use object of type PhutilSafeHTML as array" works :)

They all work for me.

I think it must be some procurement task that you all can see but I can't.

When i go to advanced search and use the same string but just additionally limit it to "Document Type: Task" the the issue is gone. So it's like it's something that is not type task.

mmodell added a comment.EditedSep 18 2020, 9:38 AM

Ok this one has got to be one of the biggest WATPHP bugs I've ever had to deal with.

So PHP supports treating strings like an array, to access single characters like

$char = $str[$i]

But, phabricator builds output using PhutilSafeHTML objects which wrap strings and ensure that everything gets encoded properly. Whenever you try to do string manipulation on one of those objects, the __toString() method converts it to an actual string. This has always worked just fine until now. For some reason PHP decided that str[$i] in this one particular context is an array dereference instead of a string index, so it threw an exception instead of calling the toString method on the PhitilSafeHTML object. Fixed with an explicit cast to string
here:

$str = (string) $str;

Mentioned in SAL (#wikimedia-operations) [2020-09-18T09:47:46Z] <twentyafterfour> deployed hotfix for T263063 to phab1001

@brennen see above for wtf php lol

Dzahn awarded a token.Sep 18 2020, 4:06 PM

see above for wtf php lol

Glorious.