As designed User Field Criteria for Notices does not handle empty criteria

Affected version
2.0.1

rfc0001

Well-known member
Specifying User value contains text: (empty) matches all values rather than empty values:

1515348648384.png

Specifying a User choice is among checkbox value and not selecting any values matches all values:

1515358517160.png
 

Mike

XenForo developer
Staff member
The first one is most definitely as designed and it has been the configuration for a long time so it wouldn't be something we'd change. Saying that, I'm pretty sure the logic is backwards as in my tests, that matches nothing (PHP's stripos always returns false if nothing is entered as the needle). Given the description though, matching only empty values wouldn't really be an expected outcome, though I understand it may be desirable. What you want is "User value is", in which case an empty string would make sense (though a naive implementation would have some caveats).

The second case is theoretically one that we could flip to match nothing as well, on the basis that you haven't selected any values and to create a parallel with the text approach, though this is also a very long standing behavior so I don't think it's necessarily beneficial to change.

In both cases, the condition without something to check for is basically nonsensical, so arguments could be made about any approach being right or wrong. Given the description and also historical behavior, I'm going to call this essentially as designed/expected.
 

rfc0001

Well-known member
In both cases, the condition without something to check for is basically nonsensical, so arguments could be made about any approach being right or wrong
If there wasn't a check box before the condition, I would agree it should be a no-op, but since you are explicitly checking the value, and leaving it blank you would think it would return matches for that condition. As it is, it does nothing, which obviously isn't useful to anyone. Having it match where values are empty would be useful. Examples are you add a custom field, and want to display a notice where that field is empty, or you want to search for users where a field (or custom field) is empty. I run into these scenarios all the time, and manually querying the database is the only solution. I'll add it under suggested feature, since it's not a bug.

ETA: It actually already is under suggested features
 
Top