phpunicodeutf-8quotes

in UTF-8 is there any multi-byte character containing the byte \x27 / chr(39) / ' / single-quote-character?


.. as the title says, in UTF-8 is there any multi-byte character containing the byte \x27 / chr(39) / ' / single-quote-character ?

you may wonder why anyone would want to know that? well, when trying to bypass the function

function quoteLinuxShellArgument(string $argument): string {
    if(false!==strpos($argument,"\x00")){error it is impossible to quote null bytes in shell arguments}
    return "'" . str_replace ( "'", "'\\''", $argument ) . "'";
}

among my first questions was the one in the title.. is there any?


Solution

  • In UTF-8, any Unicode codepoint that is outside of the ASCII range (U+0000 - U+007F) is required to be encoded using multiple bytes. All of those bytes will have their high bit set to 1.

    So no, byte 0x27 (b00100111) will never appear in a multi-byte sequence. 0x27 can only ever be used to encode codepoint U+0027 APOSTROPHE as a single byte.

    image