From 116dcf1404fd04557ef774414ca46e5c5ada582d Mon Sep 17 00:00:00 2001 From: Robert Lowe Date: Tue, 19 May 2020 07:45:17 +0100 Subject: [PATCH 1/3] Remove bad chars from filename - prevents S3 error --- component/Security/Security.php | 15 +++++++++++++++ wp-moj-components.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/component/Security/Security.php b/component/Security/Security.php index ab2f52a..b9790b7 100644 --- a/component/Security/Security.php +++ b/component/Security/Security.php @@ -16,6 +16,7 @@ public function __construct() $this->helper = $mojHelper; $this->actions(); + $this->filters(); $this->vulndb(); } @@ -24,6 +25,11 @@ public function actions() // add_action('admin_enqueue_scripts', [$this, 'enqueue']); } + public function filters() + { + add_filter('sanitize_file_name', [$this, 'remove_filename_bad_chars'], 10); + } + public function enqueue() { // wp_enqueue_style('security_admin_css', $this->helper->cssPath(__FILE__) . 'main.css', []); @@ -33,4 +39,13 @@ public static function vulndb() { return new VulnerabilityDB(); } + + public static function remove_filename_bad_chars($filename) { + + $bad_chars = array('#', '–', '~', '%', '|', '^', '>', '<', '['. ']', '{', '}'); + $filename = str_replace($bad_chars, "", $filename); + return $filename; + + } + } diff --git a/wp-moj-components.php b/wp-moj-components.php index 85b42b6..1855508 100644 --- a/wp-moj-components.php +++ b/wp-moj-components.php @@ -3,7 +3,7 @@ * Plugin name: WP MoJ Components * Plugin URI: https://github.com/ministryofjustice/wp-moj-components * Description: Introduces various functions that are commonly used across the MoJ network of sites - * Version: 3.1.1 + * Version: 3.1.2 * Author: Ministry of Justice * Text domain: wp-moj-components * Author URI: https://peoplefinder.service.gov.uk/people/damien-wilson From 9cdd684ec79805de9d99fd428b5f49ce2354c5c0 Mon Sep 17 00:00:00 2001 From: Robert Lowe Date: Tue, 19 May 2020 09:42:40 +0100 Subject: [PATCH 2/3] repalce with hypthen --- component/Security/Security.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/component/Security/Security.php b/component/Security/Security.php index b9790b7..3cce38f 100644 --- a/component/Security/Security.php +++ b/component/Security/Security.php @@ -15,26 +15,15 @@ public function __construct() global $mojHelper; $this->helper = $mojHelper; - $this->actions(); - $this->filters(); + $this->hooks(); $this->vulndb(); } - public function actions() - { - // add_action('admin_enqueue_scripts', [$this, 'enqueue']); - } - - public function filters() + public function hooks() { add_filter('sanitize_file_name', [$this, 'remove_filename_bad_chars'], 10); } - public function enqueue() - { - // wp_enqueue_style('security_admin_css', $this->helper->cssPath(__FILE__) . 'main.css', []); - } - public static function vulndb() { return new VulnerabilityDB(); @@ -42,8 +31,8 @@ public static function vulndb() public static function remove_filename_bad_chars($filename) { - $bad_chars = array('#', '–', '~', '%', '|', '^', '>', '<', '['. ']', '{', '}'); - $filename = str_replace($bad_chars, "", $filename); + $bad_chars = array( '–', '#', '~', '%', '|', '^', '>', '<', '['. ']', '{', '}'); + $filename = str_replace($bad_chars, "-", $filename); return $filename; } From 869967ffd123310e5deded96f47b9ceda83a3ec8 Mon Sep 17 00:00:00 2001 From: Robert Lowe Date: Tue, 19 May 2020 10:54:38 +0100 Subject: [PATCH 3/3] Camel Case Function --- component/Security/Security.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/component/Security/Security.php b/component/Security/Security.php index 3cce38f..b8e07cd 100644 --- a/component/Security/Security.php +++ b/component/Security/Security.php @@ -21,7 +21,7 @@ public function __construct() public function hooks() { - add_filter('sanitize_file_name', [$this, 'remove_filename_bad_chars'], 10); + add_filter('sanitize_file_name', [$this, 'removeFilenameBadChars'], 10); } public static function vulndb() @@ -29,7 +29,7 @@ public static function vulndb() return new VulnerabilityDB(); } - public static function remove_filename_bad_chars($filename) { + public static function removeFilenameBadChars($filename) { $bad_chars = array( '–', '#', '~', '%', '|', '^', '>', '<', '['. ']', '{', '}'); $filename = str_replace($bad_chars, "-", $filename);