zephir
zephir copied to clipboard
Incorrect Array Built-In Method
How to reproduce:
Variant with a->join(” “)
namespace Foo;
class Bar
{
public function test(string! a, var b = null) ->string
{
if b === null || b === false {
return a->trimleft();
}
if typeof b == "array" {
let b = b->join("");
}
let b = preg_replace("#[-\[\]:\\\\^/]#", "\\\\$0", b);
return preg_replace("/^[" . b . "]+/u", "", a);
}
}
Test 1:
php -r '$myobject = new Foo\Bar; echo $myobject->test("FOO", "F") . PHP_EOL;'
Result 1:
OO
Test 2:
php -r '$myobject = new Foo\Bar; echo $myobject->test("FOO") . PHP_EOL;'
Result 2:
FOO
Test 3:
php -r '$myobject = new Foo\Bar; echo $myobject->test("ålcó", array("å", "l")) . PHP_EOL;'
Result 3:
Segmentation fault (core dumped)
Variant with join(” “, a)
namespace Foo;
class Bar
{
public function test(string! a, var b = null) ->string
{
if b === null || b === false {
return a->trimleft();
}
if typeof b == "array" {
let b = join("", b);
}
let b = preg_replace("#[-\[\]:\\\\^/]#", "\\\\$0", b);
return preg_replace("/^[" . b . "]+/u", "", a);
}
}
Test 1:
php -r '$myobject = new Foo\Bar; echo $myobject->test("FOO", "F") . PHP_EOL;'
Result 1:
OO
Test 2:
php -r '$myobject = new Foo\Bar; echo $myobject->test("FOO") . PHP_EOL;'
Result 2:
FOO
Test 3:
php -r '$myobject = new Foo\Bar; echo $myobject->test("ålcó", array("å", "l")) . PHP_EOL;'
Result 3:
có
Resume
- With
a->join("")— Segmentation fault (core dumped) - With
join("", a)— OK
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
refs https://github.com/phalcon/zephir/pull/719