getTokens(); // Check whether this is a single quoted or double quoted string. if ($tokens[$stackPtr]['code'] === \T_CONSTANT_ENCAPSED_STRING) { // Find the start of the - potentially multi-line - text string. $start = $stackPtr; for ($i = ($stackPtr - 1); $i >= 0; $i--) { if ($tokens[$i]['code'] === \T_WHITESPACE) { continue; } if ($tokens[$i]['code'] === \T_CONSTANT_ENCAPSED_STRING) { $start = $i; continue; } break; } try { $textString = $this->getCompleteTextString($phpcsFile, $start, false); } catch (PHPCS_Exception $e) { // Something went wrong determining the start of the text string. return; } $startQuote = $textString[0]; $endQuote = substr($textString, -1); if (($startQuote === "'" && $endQuote === "'") || $startQuote !== $endQuote ) { // Single quoted string, not our concern. return; } } $content = $this->stripQuotes($tokens[$stackPtr]['content']); $count = preg_match_all('`(?isValidUnicodeEscapeSequence($match[1]); } if ($this->supportsBelow('5.6') === true && $valid === true) { $phpcsFile->addError( 'Unicode codepoint escape sequences are not supported in PHP 5.6 or earlier. Found: %s', $stackPtr, 'Found', array($match[0]) ); } if ($this->supportsAbove('7.0') === true && $valid === false) { $phpcsFile->addError( 'Strings containing a literal \u{ followed by an invalid unicode codepoint escape sequence will cause a fatal error in PHP 7.0 and above. Escape the leading backslash to prevent this. Found: %s', $stackPtr, 'Invalid', array($match[0]) ); } } } /** * Verify if the codepoint in a unicode escape sequence is valid. * * @since 9.3.0 * * @param string $codepoint The codepoint as a string. * * @return bool */ protected function isValidUnicodeEscapeSequence($codepoint) { if (trim($codepoint) === '') { return false; } // Check if it's a valid hex codepoint. if (preg_match('`^[0-9A-F]+$`iD', $codepoint, $match) !== 1) { return false; } if (hexdec($codepoint) > 1114111) { // Outside of the maximum permissable range. return false; } return true; } }