# wpfunnels/3.12.1/vendor/league/flysystem/src/WhitespacePathNormalizer.php

WPFunnels – Funnel Builder for WooCommerce with Checkout &amp; One Click Upsell, version 3.12.1. 50 lines.

- Page: https://pluginprobe.com/plugins/wpfunnels/3.12.1/code/vendor/league/flysystem/src/WhitespacePathNormalizer.php
- Raw: https://pluginprobe.com/plugins/wpfunnels/3.12.1/raw/vendor/league/flysystem/src/WhitespacePathNormalizer.php
- Modified: 2024-01-11T09:36:08+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpfunnels/3.12.1/code/vendor/league/flysystem/src/WhitespacePathNormalizer.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace League\Flysystem;

class WhitespacePathNormalizer implements PathNormalizer
{
    public function normalizePath(string $path): string
    {
        $path = str_replace('\\', '/', $path);
        $this->rejectFunkyWhiteSpace($path);

        return $this->normalizeRelativePath($path);
    }

    private function rejectFunkyWhiteSpace(string $path): void
    {
        if (preg_match('#\p{C}+#u', $path)) {
            throw CorruptedPathDetected::forPath($path);
        }
    }

    private function normalizeRelativePath(string $path): string
    {
        $parts = [];

        foreach (explode('/', $path) as $part) {
            switch ($part) {
                case '':
                case '.':
                    break;

                case '..':
                    if (empty($parts)) {
                        throw PathTraversalDetected::forPath($path);
                    }
                    array_pop($parts);
                    break;

                default:
                    $parts[] = $part;
                    break;
            }
        }

        return implode('/', $parts);
    }
}

```
