MCPcopy Create free account
hub / github.com/error311/FileRise / parseRelativePath

Method parseRelativePath

src/FileRise/Domain/UploadModel.php:599–630  ·  view source on GitHub ↗

* Parse a resumable relative path into [subDir, fileName]. * Returns [null, null] on invalid input. */

(string $raw)

Source from the content-addressed store, hash-verified

597 * Returns [null, null] on invalid input.
598 */
599 private static function parseRelativePath(string $raw): array
600 {
601 $raw = rawurldecode($raw);
602 $raw = str_replace('\\', '/', trim($raw));
603 $raw = preg_replace('/[\x00-\x1F\x7F]/', '', $raw);
604 $raw = ltrim($raw, '/');
605 if ($raw === '' || $raw === '.') {
606 return ['', ''];
607 }
608 if (preg_match('~(^|/)\.\.(?:/|$)~', $raw)) {
609 return [null, null];
610 }
611 if (preg_match('~(^|/)\.(?:/|$)~', $raw)) {
612 return [null, null];
613 }
614
615 $file = basename($raw);
616 if (!UploadNamePolicy::isAllowedForWrite($file)) {
617 return [null, null];
618 }
619
620 $dir = dirname($raw);
621 if ($dir === '.' || $dir === '') {
622 return ['', $file];
623 }
624
625 if (!preg_match(REGEX_FOLDER_NAME, $dir)) {
626 return [null, null];
627 }
628
629 return [$dir, $file];
630 }
631
632 private static function portalMetaFromRequest(): ?array
633 {

Callers 2

handleUploadMethod · 0.95
checkExistingMethod · 0.95

Calls 1

isAllowedForWriteMethod · 0.80

Tested by

no test coverage detected