Skip to content

Commit 1fa76e8

Browse files
add function is_blank() to see if var is either null, '', or whitespace
1 parent ee8692b commit 1fa76e8

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

html/inc/db.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ function db_init_aux($try_replica=false) {
168168
if ($x) $db_name = $x;
169169
}
170170
}
171-
if (!$host) {
171+
if (is_blank($host)) {
172172
$host = parse_config($config, "<db_host>");
173173
}
174-
if (!$host) {
174+
if (is_blank($host)) {
175175
$host = "localhost";
176176
}
177177
if (1) {

html/inc/util_basic.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ function time_diff($x, $res=3) {
242242
return $s;
243243
}
244244

245+
// is the arg either null, '', or whitespace?
246+
// Note: if ($x) will be false if $x is '0'.
247+
// We don't want to treat '0' as blank.
248+
//
249+
function is_blank($x) {
250+
return $x === null || trim($x) === '';
251+
}
245252

246253
// security vulnerabilities and user-supplied strings:
247254
// sources:

html/inc/util_ops.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function db_init_cli() {
103103
$config = get_config();
104104
$db_name = parse_config($config, "<db_name>");
105105
$host = parse_config($config, "<db_host>");
106-
if (!$host) {
106+
if (is_blank($host)) {
107107
$host = "localhost";
108108
}
109109
$in = fopen("php://stdin","r");

html/user/pm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function do_send_team($logged_in_user) {
199199
error_page("no team admin");
200200
}
201201

202-
if (!$subject || !$content) {
202+
if (is_blank($subject) || is_blank($content)) {
203203
pm_team_form(
204204
$logged_in_user, $teamid,
205205
tra("You need to fill all fields to send a private message")
@@ -235,7 +235,7 @@ function do_send($logged_in_user) {
235235
pm_form_page($replyto, $userid);
236236
return;
237237
}
238-
if (!$to || !$subject || !$content ) {
238+
if (is_blank($to) || is_blank($subject) || is_blank($content)) {
239239
pm_form_page(
240240
$replyto, $userid,
241241
tra("You need to fill all fields to send a private message")

0 commit comments

Comments
 (0)