Skip to content

Commit

Permalink
:octocat: allow for ECI encoded numeric and alphanum segments (???), see #289
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Nov 16, 2024
1 parent 052c7c6 commit 1d8b7fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
22 changes: 14 additions & 8 deletions src/Data/ECI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1d8b7fd

Please sign in to comment.