Skip to content

Commit dd17029

Browse files
committed
Add demojibakefier support.
1 parent 6f612b5 commit dd17029

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

src/Web.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Upload handler (last modified: 2020.07.13).
11+
* This file: Upload handler (last modified: 2020.07.16).
1212
*/
1313

1414
namespace phpMussel\Web;
@@ -146,13 +146,13 @@ public function scan()
146146
$FilesToScan = [];
147147

148148
/** Iterate through $_FILES array and scan as necessary. */
149-
foreach ($_FILES as $FileKey => $FileData) {
149+
foreach ($_FILES as $FileData) {
150150
/** Guard. */
151151
if (!isset($FileData['error'])) {
152152
continue;
153153
}
154154

155-
/** Normalise the structure of the uploads array. */
155+
/** Normalise the structure of the files array. */
156156
if (!is_array($FileData['error'])) {
157157
$FilesData['FileSet'] = [
158158
'name' => [$FileData['name']],
@@ -263,7 +263,7 @@ public function scan()
263263
}
264264

265265
/** Exit here if there aren't any file upload detections. */
266-
if (count($this->Loader->ScanResultsText) < 1) {
266+
if (empty($this->Loader->InstanceCache['DetectionsCount'])) {
267267
return;
268268
}
269269

@@ -399,4 +399,43 @@ public function scan()
399399
/** Send HTML output and the kill the script. */
400400
die($Output);
401401
}
402+
403+
/**
404+
* A method provided for running the names of uploaded files through the
405+
* demojibakefier for the optional use of the implementation (warning: this
406+
* will modify the "name" value of the entries in $_FILES).
407+
*
408+
* @param string $Encoding The implementation may optionally specify the
409+
* preferred encoding for the demojibakefier to normalise names to. It
410+
* is generally recommended to leave it at its default, however.
411+
*/
412+
public function demojibakefier(string $Encoding = 'UTF-8')
413+
{
414+
/** Instantiate the demojibakefier class. */
415+
$Demojibakefier = new \Maikuolan\Common\Demojibakefier($Encoding);
416+
417+
/** Exit early if there isn't anything to run through. */
418+
if (!$this->Uploads) {
419+
return;
420+
}
421+
422+
/** Iterate through the $_FILES array. */
423+
foreach ($_FILES as &$FileData) {
424+
/** Guard. */
425+
if (!isset($FileData['name'])) {
426+
continue;
427+
}
428+
429+
/** Run the names through the demojibakefier. */
430+
if (is_array($FileData['name'])) {
431+
foreach ($FileData['name'] as &$FileName) {
432+
if (is_string($FileName)) {
433+
$FileName = $Demojibakefier->guard($FileName);
434+
}
435+
}
436+
} elseif (is_string($FileData['name'])) {
437+
$FileData['name'] = $Demojibakefier->guard($FileData['name']);
438+
}
439+
}
440+
}
402441
}

0 commit comments

Comments
 (0)