Page MenuHomePhabricator

D9213.id21881.diff
No OneTemporary

D9213.id21881.diff

diff --git a/src/utils/__tests__/PhutilUtilsTestCase.php b/src/utils/__tests__/PhutilUtilsTestCase.php
--- a/src/utils/__tests__/PhutilUtilsTestCase.php
+++ b/src/utils/__tests__/PhutilUtilsTestCase.php
@@ -168,6 +168,25 @@
array(),
array(4, 5),
)));
+
+ $not_valid = array(
+ 'scalar' => array(1),
+ 'array plus scalar' => array(array(), 1),
+ 'null' => array(null),
+ );
+
+ foreach ($not_valid as $key => $invalid_input) {
+ $caught = null;
+ try {
+ array_mergev($invalid_input);
+ } catch (InvalidArgumentException $ex) {
+ $caught = $ex;
+ }
+
+ $this->assertTrue(
+ ($caught instanceof InvalidArgumentException),
+ "array_mergev() invalid on {$key}");
+ }
}
public function testNonempty() {
diff --git a/src/utils/utils.php b/src/utils/utils.php
--- a/src/utils/utils.php
+++ b/src/utils/utils.php
@@ -732,6 +732,17 @@
return array();
}
+ foreach ($arrayv as $key => $item) {
+ if (!is_array($item)) {
+ throw new InvalidArgumentException(
+ pht(
+ 'Expected all items passed to array_mergev() to be arrays, but '.
+ 'argument with key "%s" has type "%s".',
+ $key,
+ gettype($item)));
+ }
+ }
+
return call_user_func_array('array_merge', $arrayv);
}

File Metadata

Mime Type
text/plain
Expires
Wed, Oct 16, 3:37 PM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6718077
Default Alt Text
D9213.id21881.diff (1 KB)

Event Timeline