Page MenuHomePhabricator

Improve documentation of added_lines and similar variables (are they strings or arrays?)
Closed, ResolvedPublic

Description

While testing T168736 at /examine I noticed that

   'x' in added_lines
& length( added_lines ) === 1
& added_lines rlike '^x$'

matches this test edit (where I replaced a line having a 'c' by a line having an 'x'). However,

added_lines == 'x'

does not match the edit. As far as I can see, it should match.

Also, when I type wgAbuseFilterVariables.added_lines in the JavaScript console I get:

Array [ "x" ]

So, I assume it is an array, but when I try (in /examine, not in the console)

added_lines == ['x']

it does not match, even though

added_lines in ['x'] & ['x'] in added_lines

matches.

I would really like to know (and document) what exactly is added_lines triple-equals to

Event Timeline

He7d3r created this task.Oct 28 2017, 5:06 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 28 2017, 5:06 PM
Daimona claimed this task.EditedMar 25 2018, 9:16 AM
Daimona triaged this task as Normal priority.
Daimona added a subscriber: Daimona.

Let's sum up. The length thing is out of this task and was addressed in another place. Now, we remain with two problems:

  1. added_lines == 'x' is false
  2. added_lines == ['x'] is false as well

About (1): I think this is intended, since added_lines is an array (and I documented it today). You can use functions like rlike, in, contains and so on, but you can't expect to get a truly for equality of a string and an array. In case you want to perform such check, you should instead do string(added_lines) == 'x'. Right now it doesn't work, but this is a bug already addressed in T190639. After its resolution, the cast will work fine.

About (2): this is the real problem here. It's probably due to some mess with lists somewhere, and I'm going to find it. I'll let you know.

OH WOW! I found the reason and it's super weird. The equality function explicitly returns false if even one of the arguments is a list. The fix is pretty simple, especially if we limit it to treat the cases NOT LIST == NOT LIST and LIST == LIST, but first I'd like to investigate about the reason of such exclusion.

Change 421786 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/AbuseFilter@master] Allow comparing two lists

https://gerrit.wikimedia.org/r/421786

As I said on gerrit, prior to merging this patch we need to figure out why array comparison wasn't allowed and whether we risk to break existing filters.

Change 421786 merged by jenkins-bot:
[mediawiki/extensions/AbuseFilter@master] Allow comparing two lists

https://gerrit.wikimedia.org/r/421786

Daimona closed this task as Resolved.Apr 6 2018, 9:18 PM
Daimona removed a project: Patch-For-Review.

The specific problem is solved. Plus, now it's possible to compare any couple of list with reliable results.