@@ -124,17 +124,23 @@ public static function validateString(string $string):bool{
124124 public static function decodeSegment (BitBuffer $ bitBuffer , int $ versionNumber ):string {
125125 $ eciCharset = self ::parseValue ($ bitBuffer );
126126 $ nextMode = $ bitBuffer ->read (4 );
127-
128- if ($ nextMode !== Mode::BYTE ){
129- throw new QRCodeDataException (sprintf ('ECI designator followed by invalid mode: "%04b" ' , $ nextMode ));
130- }
131-
132- $ data = Byte::decodeSegment ($ bitBuffer , $ versionNumber );
133- $ encoding = $ eciCharset ->getName ();
127+ $ encoding = $ eciCharset ->getName ();
128+
129+ // this is definitely weird, but there are QR Codes out in the wild
130+ // that have ECI followed by numeric and alphanum segments
131+ // @see https://github.com/chillerlan/php-qrcode/discussions/289
132+ $ data = match ($ nextMode ){
133+ Mode::NUMBER => Number::decodeSegment ($ bitBuffer , $ versionNumber ),
134+ Mode::ALPHANUM => AlphaNum::decodeSegment ($ bitBuffer , $ versionNumber ),
135+ Mode::BYTE => Byte::decodeSegment ($ bitBuffer , $ versionNumber ),
136+ default => throw new QRCodeDataException (
137+ sprintf ('ECI designator followed by invalid mode: "%04b" ' , $ nextMode ),
138+ ),
139+ };
134140
135141 if ($ encoding === null ){
136142 // The spec isn't clear on this mode; see
137- // section 6.4.5: t does not say which encoding to assuming
143+ // section 6.4.5: it does not say which encoding to assuming
138144 // upon decoding. I have seen ISO-8859-1 used as well as
139145 // Shift_JIS -- without anything like an ECI designator to
140146 // give a hint.
0 commit comments