Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This is the code for InOperator::validate():
elseif (!empty($this->value) && ($this->operator == 'in' || $this->operator == 'not in')) {
$errors[] = $this->t('The value @value is not an array for @operator on filter: @filter', ['@value' => var_export($this->value), '@operator' => $this->operator, '@filter' => $this->adminLabel(TRUE)]);
}
It want use var_export to get the parsable string for value, but forgot the second parameter, so it will outputs the string and break the JSON output format for AJAX call.
Proposed resolution
Fix it.
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff_11-16.txt | 562 bytes | ravi.shankar |
#16 | 3074595-16.patch | 2.28 KB | ravi.shankar |
#11 | 3074595-11.patch | 2.28 KB | Lendude |
#11 | 3074595-11-TEST_ONLY.patch | 1.39 KB | Lendude |
#7 | issue-3074595-7.patch | 812 bytes | sime |
Comments
Comment #2
jian he CreditAttribution: jian he commentedComment #5
Kristen PolPatch still applies to 9.1.x.
Comment #6
Kristen PolThanks for the issue and patch.
1) Checked all of core and the only place not using
TRUE
isInOperator.php
.2) Kicking off tests for 9.1.x.
3) Is there a way to test this manually?
Comment #7
simeI agree the code won't work as expected but I assume the filter UI (eg checkboxes) ensures this value is always an array. So I can't think of a way to reproduce this through the UI.
I also can't find any tests that cover this piece of code. I removed the whole clause and I ran a few of the coverage tests, and nothing failed.
Posting a patch that removes the entire clause just to see if any tests fail.
Comment #8
simeAssigned myself for follow up. Find me in #bugsmash if I'm tardy.
Comment #9
simeSo the tests pass if we remove that piece of code. I think at the very least it needs a test. Although I'm of the opinion the code never gets triggered unless a filter plugin has been badly coded.
Comment #10
simeLooking for some feedback here, not sure how to functional/kernel test this if all the related methods are setting the ->value correctly as an array. So maybe a unit test? But I don't see any existing unit tests for this code... i don't think. Perhaps the patch is fine as is.
Comment #11
LendudeLet's add a unit test for this.
I would say the best way forward here is #2. While I like removing things, I think this is a valid check. We would lose some developer feedback if this would just silently pass validation even when the value is invalid (even if this can only be achieved with bad code).
Comment #13
simeThanks @lendude, I've learned from this.
Tested the patch locally and it looks RTBC.
Comment #14
init90Comment #15
longwaveNit: static public -> public static
Comment #16
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedFixed comment #15.
Comment #17
longwaveThanks, back to RTBC :)
Comment #20
larowlanCommitted 98856bb and pushed to 9.1.x. Thanks!
C/p to 9.0
Kicking a test-run off for 8.9.x for possible backport
Comment #22
larowlanc/p to 8.9.x - thanks