Skip to content
Snippets Groups Projects
Commit 5d0aaf95 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

treat empty string inputs as unset for int and bool

parent 0189bd86
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,11 @@ class input_test extends DokuWikiTest {
$this->assertSame(1, $INPUT->get->int('get', false));
$this->assertSame(0, $INPUT->int('array'));
$this->assertSame(0, $INPUT->int('zero', -1));
$this->assertSame(-1, $INPUT->int('empty', -1));
$this->assertSame(-1, $INPUT->int('zero', -1, true));
$this->assertSame(-1, $INPUT->int('empty', -1, true));
}
public function test_arr() {
......@@ -155,6 +160,11 @@ class input_test extends DokuWikiTest {
$this->assertSame(false, $INPUT->post->bool('get'));
$this->assertSame(true, $INPUT->post->bool('post'));
$this->assertSame(false, $INPUT->bool('zero', -1));
$this->assertSame(-1, $INPUT->bool('empty', -1));
$this->assertSame(-1, $INPUT->bool('zero', -1, true));
$this->assertSame(-1, $INPUT->bool('empty', -1, true));
}
public function test_remove() {
......@@ -203,4 +213,4 @@ class input_test extends DokuWikiTest {
$this->assertEquals('bla',$test);
}
}
\ No newline at end of file
}
......@@ -118,6 +118,7 @@ class Input {
public function int($name, $default = 0, $nonempty = false) {
if(!isset($this->access[$name])) return $default;
if(is_array($this->access[$name])) return $default;
if($this->access[$name] === '') return $default;
if($nonempty && empty($this->access[$name])) return $default;
return (int) $this->access[$name];
......@@ -151,6 +152,8 @@ class Input {
*/
public function bool($name, $default = false, $nonempty = false) {
if(!isset($this->access[$name])) return $default;
if(is_array($this->access[$name])) return $default;
if($this->access[$name] === '') return $default;
if($nonempty && empty($this->access[$name])) return $default;
return (bool) $this->access[$name];
......@@ -223,4 +226,4 @@ class GetInput extends Input {
parent::set($name, $value);
$_REQUEST[$name] = $value;
}
}
\ No newline at end of file
}
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