Fixed JavaScript code for detecting the need for a larger QR Code version, due to incorrect code simplification in commit 5692e951dd.

This commit is contained in:
Nayuki Minase 2016-04-18 19:39:32 +00:00
parent 3878c12a81
commit c55751e7bd
1 changed files with 3 additions and 2 deletions

View File

@ -778,13 +778,14 @@ var qrcodegen = new function() {
if (version < 1 || version > 40) if (version < 1 || version > 40)
throw "Version number out of range"; throw "Version number out of range";
var result = 0; var result = 0;
segs.forEach(function(seg) { for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
var ccbits = seg.getMode().numCharCountBits(version); var ccbits = seg.getMode().numCharCountBits(version);
// Fail if segment length value doesn't fit in the length field's bit-width // Fail if segment length value doesn't fit in the length field's bit-width
if (seg.getNumChars() >= (1 << ccbits)) if (seg.getNumChars() >= (1 << ccbits))
return null; return null;
result += 4 + ccbits + seg.getBits().length; result += 4 + ccbits + seg.getBits().length;
}); }
return result; return result;
}; };