Skip to content

Commit 294312e

Browse files
committed
Fix TrimLeadingZeros
1 parent 03174ac commit 294312e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

QRCoder/QRCodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void WriteEccLevelAndVersion()
373373
#endif
374374
private static void TrimLeadingZeros(BitArray fStrEcc, ref int index, ref int count)
375375
{
376-
while (!fStrEcc[index])
376+
while (count > 0 && !fStrEcc[index])
377377
{
378378
index++;
379379
count--;

QRCoderTests/QRGeneratorTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ public void can_generate_from_bytes()
191191
result.ShouldBe("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111011001011111110000000010000010010010100000100000000101110101010101011101000000001011101010010010111010000000010111010111000101110100000000100000100000001000001000000001111111010101011111110000000000000000011000000000000000000111100101010010011101000000001011100001001001001110000000010101011111011111110100000000000101000000110000000000000001011001001010100110000000000000000000110001000101000000000111111100110011011110000000001000001001111110111010000000010111010011100100101100000000101110101110010010010000000001011101011010100011000000000010000010110110101000100000000111111101011100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
192192
}
193193

194+
[Fact]
195+
[Category("QRGenerator/TextEncoding")]
196+
public void trim_leading_zeros_works()
197+
{
198+
var gen = new QRCodeGenerator();
199+
var qrData = gen.CreateQrCode("this is a test", QRCodeGenerator.ECCLevel.M);
200+
var result = string.Join("", qrData.ModuleMatrix.Select(x => x.ToBitString()).ToArray());
201+
result.ShouldBe("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111001101011111110000000010000010010000100000100000000101110101101101011101000000001011101010001010111010000000010111010101010101110100000000100000101010101000001000000001111111010101011111110000000000000000110010000000000000000101111100011101111100000000001110100011110001100010000000001100011010110010011000000000100111000011010011100000000001001011001101011000100000000000000000100100001001100000000111111100111110001110000000001000001010011000011010000000010111010101110111101100000000101110101000000110100000000001011101011111000010000000000010000010010011010010000000000111111101101111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
202+
}
203+
194204
[Fact]
195205
[Category("QRGenerator/TextEncoding")]
196206
public void isValidIso_works()

0 commit comments

Comments
 (0)