From 71fc7a47919c727a1885d037fc87afd463cfd68a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 7 Aug 2019 21:23:29 +0200 Subject: [PATCH] Use preg_split() instead of explode() for better space handling. Skip empty domains in add_to_table() and remove_from_table(). Signed-off-by: DL6ER --- scripts/pi-hole/php/add.php | 2 +- scripts/pi-hole/php/database.php | 8 ++++++++ scripts/pi-hole/php/sub.php | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index 58f68e76..94a17345 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -24,7 +24,7 @@ if(in_array($list, $check_lists)) { } // Split individual domains into array -$domains = explode(" ",$_POST['domain']); +$domains = preg_split('/\s+/', $_POST['domain']); require_once("func.php"); require_once("database.php"); diff --git a/scripts/pi-hole/php/database.php b/scripts/pi-hole/php/database.php index 878f6df8..3304bec5 100644 --- a/scripts/pi-hole/php/database.php +++ b/scripts/pi-hole/php/database.php @@ -81,6 +81,10 @@ function add_to_table($db, $table, $domains, $wildcardstyle=false) $num = 0; foreach($domains as $domain) { + // Skip empty domains + if(strlen($domain) == 0) + continue; + if($wildcardstyle) $domain = "(\\.|^)".str_replace(".","\\.",$domain)."$"; @@ -124,6 +128,10 @@ function remove_from_table($db, $table, $domains) $num = 0; foreach($domains as $domain) { + // Skip empty domains + if(strlen($domain) == 0) + continue; + $stmt->bindValue(":domain", $domain, SQLITE3_TEXT); if($stmt->execute() && $stmt->reset()) diff --git a/scripts/pi-hole/php/sub.php b/scripts/pi-hole/php/sub.php index fba80af4..0030b4dd 100644 --- a/scripts/pi-hole/php/sub.php +++ b/scripts/pi-hole/php/sub.php @@ -17,7 +17,7 @@ if (empty($api)) { } // Split individual domains into array -$domains = explode(" ",$_POST['domain']); +$domains = preg_split('/\s+/', $_POST['domain']); require_once("func.php");