Skip to content

Commit 00b403e

Browse files
authored
Merge pull request #120 from aaronjorbin/fix/119
Cast "1" and "0" as booleans when they are expected as booleans.
2 parents 4dd5278 + badf31f commit 00b403e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Plugin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ public function buildPHPConfig()
350350
} else if (isset($config[$setting]) && $config[$setting] === 'true') {
351351
$config[$setting] = true;
352352
}
353+
354+
// also handle 1 and 0 as booleans
355+
else if (isset($config[$setting]) && $config[$setting] === '0') {
356+
$config[$setting] = false;
357+
} else if (isset($config[$setting]) && $config[$setting] === '1') {
358+
$config[$setting] = true;
359+
}
353360
}
354361

355362
return $config;

tests/PluginTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public function testLoggingLevel(
6161
}
6262

6363
}
64+
65+
/**
66+
* Tests to ensure bools are properly converted from "1" and "0" strings
67+
*
68+
* @ticket https://github.com/rollbar/rollbar-php-wordpress/issues/119
69+
*/
70+
public function testSendMessageTraceBool(){
71+
$plugin = $this->subject;
72+
73+
$plugin->setting( 'send_message_trace', '1' );
74+
$plugin->setting( 'report_suppressed', '0' );
75+
$data = $plugin->buildPHPConfig();
76+
77+
$this->assertTrue( $data['send_message_trace'] );
78+
$this->assertFalse( $data['report_suppressed'] );
79+
}
6480

6581
public static function loggingLevelTestDataProvider()
6682
{

0 commit comments

Comments
 (0)