@@ -43,7 +43,8 @@ public static function validate($input)
4343 {
4444 // Fast-path
4545 // But before PHP 5.4 Unicode support has bugs.
46- if (PHP_VERSION_ID >= 50400 ) {
46+ $ useFastPath = PHP_VERSION_ID >= 50400 ;
47+ if ($ useFastPath ) {
4748 if (function_exists ("mb_check_encoding " )) {
4849 if (mb_check_encoding ($ input , 'UTF-8 ' )) {
4950 return ;
@@ -294,6 +295,30 @@ public static function validate($input)
294295 true
295296 );
296297 }
298+ // The fast-path flagged this input as invalid UTF-8, yet the manual RFC 3629
299+ // scan above found no fault. The two must always agree, so reaching here means
300+ // the fast-path caught something the scan missed - surface it rather than
301+ // silently accepting the input as valid.
302+ if ($ useFastPath ) {
303+ throw new InvalidEncodingException (
304+ "Fast-path detected an error that the manual scan could not find. "
305+ ."Please report it at https://github.com/Seldaek/jsonlint/issues. " ,
306+ "0 " ,
307+ array (
308+ 'current_octet ' => $ currentOctet ,
309+ 'continuation_octet_needed ' => $ continuationOctetNeeded ,
310+ 'offset_in_octets_from_string_start ' => $ offsetInOctetsFromStringStart ,
311+ 'offset_in_characters_from_string_start ' => $ offsetInCharactersFromStringStart ,
312+ 'character_start_position_from_string_start ' => $ characterStartPositionFromStringStart ,
313+ 'line ' => $ currentLineNumber ,
314+ 'offset_in_octets_from_line_start ' => $ offsetInOctetsFromLineStart ,
315+ 'offset_in_characters_from_line_start ' => $ offsetInCharactersFromLineStart ,
316+ 'character_start_position_from_line_start ' => $ characterStartPositionFromLineStart ,
317+ 'current_continuation_octet_minimum ' => $ currentContinuationOctetMinimum ,
318+ 'current_continuation_octet_maximum ' => $ currentContinuationOctetMaximum ,
319+ )
320+ );
321+ }
297322 }
298323
299324 /**
0 commit comments