diff options
author | cash <cash.costello@gmail.com> | 2013-03-30 12:04:19 -0400 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2013-03-30 12:04:19 -0400 |
commit | cb8a932702a66a8d8ec69982441e71bde8fd1b5c (patch) | |
tree | bc64124e9fa6675ab509a88b2a2275eff7028446 /engine | |
parent | d167a3b62afd6c07cf6c9257c49d5dd77958a58e (diff) | |
download | elgg-cb8a932702a66a8d8ec69982441e71bde8fd1b5c.tar.gz elgg-cb8a932702a66a8d8ec69982441e71bde8fd1b5c.tar.bz2 |
Fixes #4867 handling boolean false values as metadata pair value
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/metadata.php | 2 | ||||
-rw-r--r-- | engine/tests/api/metadata.php | 14 |
2 files changed, 16 insertions, 0 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index a1ebfa5f1..ad926a49a 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -619,6 +619,8 @@ $owner_guids = NULL) { // if the operand is IN don't quote it because quoting should be done already. if (is_numeric($pair['value'])) { $value = sanitise_string($pair['value']); + } else if (is_bool($pair['value'])) { + $value = (int) $pair['value']; } else if (is_array($pair['value'])) { $values_array = array(); diff --git a/engine/tests/api/metadata.php b/engine/tests/api/metadata.php index 825290d80..0862341c1 100644 --- a/engine/tests/api/metadata.php +++ b/engine/tests/api/metadata.php @@ -123,6 +123,20 @@ class ElggCoreMetadataAPITest extends ElggCoreUnitTest { $e->delete(); } + /** + * https://github.com/Elgg/Elgg/issues/4867 + */ + public function testElggGetEntityMetadataWhereSqlWithFalseValue() { + $pair = array('name' => 'test' , 'value' => false); + $result = elgg_get_entity_metadata_where_sql('e', 'metadata', null, null, $pair); + $where = preg_replace( '/\s+/', ' ', $result['wheres'][0]); + $this->assertTrue(strpos($where, "msn1.string = 'test' AND BINARY msv1.string = 0") > 0); + + $result = elgg_get_entity_metadata_where_sql('e', 'metadata', array('test'), array(false)); + $where = preg_replace( '/\s+/', ' ', $result['wheres'][0]); + $this->assertTrue(strpos($where, "msn.string IN ('test')) AND ( BINARY msv.string IN ('0')")); + } + // Make sure metadata with multiple values is correctly deleted when re-written // by another user // http://trac.elgg.org/ticket/2776 |