Skip to content
Snippets Groups Projects
Commit eb56c4d3 authored by catch's avatar catch
Browse files

Issue #2299215 by jhedstrom, torrance123: Fixed 'extra' join conditions leaking arguments.

parent b1e36444
No related branches found
No related tags found
No related merge requests found
......@@ -244,13 +244,15 @@ public function buildJoin($select_query, $table, $view_query) {
if (is_array($info['value'])) {
// With an array of values, we need multiple placeholders and the
// 'IN' operator is implicit.
$local_arguments = array();
foreach ($info['value'] as $value) {
$placeholder_i = ':views_join_condition_' . $select_query->nextPlaceholder();
$arguments[$placeholder_i] = $value;
$local_arguments[$placeholder_i] = $value;
}
$operator = !empty($info['operator']) ? $info['operator'] : 'IN';
$placeholder = '( ' . implode(', ', array_keys($arguments)) . ' )';
$placeholder = '( ' . implode(', ', array_keys($local_arguments)) . ' )';
$arguments += $local_arguments;
}
else {
// With a single value, the '=' operator is implicit.
......
......@@ -141,7 +141,7 @@ public function testBasePlugin() {
'field' => 'name',
'value' => $random_name_2,
'operator' => '<>'
)
),
);
$join = $this->manager->createInstance('standard', $configuration);
$table = array('alias' => 'users3');
......@@ -152,6 +152,29 @@ public function testBasePlugin() {
$this->assertTrue(strpos($join_info['condition'], "users3.name = :views_join_condition_0") !== FALSE, 'Make sure the first extra join condition appears in the query and uses the first placeholder.');
$this->assertTrue(strpos($join_info['condition'], "users3.name <> :views_join_condition_1") !== FALSE, 'Make sure the second extra join condition appears in the query and uses the second placeholder.');
$this->assertEqual(array_values($join_info['arguments']), array($random_name_1, $random_name_2), 'Make sure the arguments are in the right order');
// Test that 'IN' conditions are properly built.
$random_name_1 = $this->randomMachineName();
$random_name_2 = $this->randomMachineName();
$random_name_3 = $this->randomMachineName();
$random_name_4 = $this->randomMachineName();
$configuration['extra'] = array(
array(
'field' => 'name',
'value' => $random_name_1
),
array(
'field' => 'name',
'value' => array($random_name_2, $random_name_3, $random_name_4),
),
);
$join = $this->manager->createInstance('standard', $configuration);
$table = array('alias' => 'users4');
$join->buildJoin($query, $table, $view->query);
$tables = $query->getTables();
$join_info = $tables['users4'];
$this->assertTrue(strpos($join_info['condition'], "users4.name IN ( :views_join_condition_3, :views_join_condition_4, :views_join_condition_5 )") !== FALSE, 'The IN condition for the join is properly formed.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment