Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/Seld/JsonLint/Utf8Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static function validate($input)
{
// Fast-path
// But before PHP 5.4 Unicode support has bugs.
if (PHP_VERSION_ID >= 50400) {
$useFastPath = PHP_VERSION_ID >= 50400;
if ($useFastPath) {
if (function_exists("mb_check_encoding")) {
if (mb_check_encoding($input, 'UTF-8')) {
return;
Expand Down Expand Up @@ -294,6 +295,30 @@ public static function validate($input)
true
);
}
// The fast-path flagged this input as invalid UTF-8, yet the manual RFC 3629
// scan above found no fault. The two must always agree, so reaching here means
// the fast-path caught something the scan missed - surface it rather than
// silently accepting the input as valid.
if ($useFastPath) {
throw new InvalidEncodingException(
"Fast-path detected an error that the manual scan could not find. "
."Please report it at https://github.com/Seldaek/jsonlint/issues.",
"0",
array(
'current_octet' => $currentOctet,
'continuation_octet_needed' => $continuationOctetNeeded,
'offset_in_octets_from_string_start' => $offsetInOctetsFromStringStart,
'offset_in_characters_from_string_start' => $offsetInCharactersFromStringStart,
'character_start_position_from_string_start' => $characterStartPositionFromStringStart,
'line' => $currentLineNumber,
'offset_in_octets_from_line_start' => $offsetInOctetsFromLineStart,
'offset_in_characters_from_line_start' => $offsetInCharactersFromLineStart,
'character_start_position_from_line_start' => $characterStartPositionFromLineStart,
'current_continuation_octet_minimum' => $currentContinuationOctetMinimum,
'current_continuation_octet_maximum' => $currentContinuationOctetMaximum,
)
);
}
}

/**
Expand Down