CoreFiles by mySites.guru
InsignificantNonSubstringSpaceStep.php32 lines, 1,033 bytes, from Joomla_6.1.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 6.1.0-alpha1
md5
c10c73e829b338c572375d5ca64d7a6e
sha1
51b118c45df2b962d4f294b1534346fe49b808a4
sha256
5bd9a617410a9b0b7b03ca2286600f805a044f62bbcdb143ca11fd54f6f4ad8c
<?php

declare(strict_types=1);

namespace SpomkyLabs\Pki\X501\StringPrep;

/**
 * Implements 'Insignificant Space Handling' step of the Internationalized String Preparation as specified by RFC 4518.
 *
 * This variant handles input strings that are non-substring assertion values.
 *
 * @see https://tools.ietf.org/html/rfc4518#section-2.6.1
 */
final class InsignificantNonSubstringSpaceStep implements PrepareStep
{
    /**
     * @param string $string UTF-8 encoded string
     */
    public function apply(string $string): string
    {
        // if value contains no non-space characters
        if (preg_match('/^\p{Zs}*$/u', $string) === 1) {
            return '  ';
        }
        // trim leading and trailing spaces
        $string = preg_replace('/^\p{Zs}+/u', '', $string);
        $string = preg_replace('/\p{Zs}+$/u', '', (string) $string);
        // convert inner space sequences to two U+0020 characters
        $string = preg_replace('/\p{Zs}+/u', '  ', (string) $string);
        return " {$string} ";
    }
}

The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.