summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-06-28 17:17:24 +0200
committerAndreas Gohr <andi@splitbrain.org>2012-06-29 00:12:22 +0200
commit5d0aaf958325f500ce69cfb79e69eb0d8f83fdeb (patch)
tree96236bc76befde8b5eefe62c2c3ac5cb87141cc4
parent0189bd8669742c5290a4f6538f954b81554e26d2 (diff)
downloadrpg-5d0aaf958325f500ce69cfb79e69eb0d8f83fdeb.tar.gz
rpg-5d0aaf958325f500ce69cfb79e69eb0d8f83fdeb.tar.bz2
treat empty string inputs as unset for int and bool
-rw-r--r--_test/tests/inc/input.test.php12
-rw-r--r--inc/Input.class.php5
2 files changed, 15 insertions, 2 deletions
diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php
index 627af3a2b..761b7ddbc 100644
--- a/_test/tests/inc/input.test.php
+++ b/_test/tests/inc/input.test.php
@@ -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
+}
diff --git a/inc/Input.class.php b/inc/Input.class.php
index 1ea5e031f..f4174404a 100644
--- a/inc/Input.class.php
+++ b/inc/Input.class.php
@@ -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
+}