diff --git a/examples/reader.php b/examples/reader.php index 0986beb82..4ec6c1560 100644 --- a/examples/reader.php +++ b/examples/reader.php @@ -25,7 +25,7 @@ var_dump($result); } catch(Throwable $e){ - echo $e->getMessage(); + printf("%s(%s): %s\n%s", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getTraceAsString()); } exit; diff --git a/src/Data/ECI.php b/src/Data/ECI.php index c1d4021f5..35a4e88ad 100644 --- a/src/Data/ECI.php +++ b/src/Data/ECI.php @@ -124,17 +124,23 @@ public static function validateString(string $string):bool{ public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{ $eciCharset = self::parseValue($bitBuffer); $nextMode = $bitBuffer->read(4); - - if($nextMode !== Mode::BYTE){ - throw new QRCodeDataException(sprintf('ECI designator followed by invalid mode: "%04b"', $nextMode)); - } - - $data = Byte::decodeSegment($bitBuffer, $versionNumber); - $encoding = $eciCharset->getName(); + $encoding = $eciCharset->getName(); + + // this is definitely weird, but there are QR Codes out in the wild + // that have ECI followed by numeric and alphanum segments + // @see https://github.com/chillerlan/php-qrcode/discussions/289 + $data = match($nextMode){ + Mode::NUMBER => Number::decodeSegment($bitBuffer, $versionNumber), + Mode::ALPHANUM => AlphaNum::decodeSegment($bitBuffer, $versionNumber), + Mode::BYTE => Byte::decodeSegment($bitBuffer, $versionNumber), + default => throw new QRCodeDataException( + sprintf('ECI designator followed by invalid mode: "%04b"', $nextMode), + ), + }; if($encoding === null){ // The spec isn't clear on this mode; see - // section 6.4.5: t does not say which encoding to assuming + // section 6.4.5: it does not say which encoding to assuming // upon decoding. I have seen ISO-8859-1 used as well as // Shift_JIS -- without anything like an ECI designator to // give a hint.