Skip to content

Commit

Permalink
Merge pull request #527 from Shane32/fix_trim_leading_zeros
Browse files Browse the repository at this point in the history
Fix TrimLeadingZeros
  • Loading branch information
codebude authored May 19, 2024
2 parents 283a458 + b640adb commit 276e4ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion QRCoder/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void WriteEccLevelAndVersion()
#endif
private static void TrimLeadingZeros(BitArray fStrEcc, ref int index, ref int count)
{
while (!fStrEcc[index])
while (count > 0 && !fStrEcc[index])
{
index++;
count--;
Expand Down
10 changes: 10 additions & 0 deletions QRCoderTests/QRGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ public void can_generate_from_bytes()
result.ShouldBe("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111011001011111110000000010000010010010100000100000000101110101010101011101000000001011101010010010111010000000010111010111000101110100000000100000100000001000001000000001111111010101011111110000000000000000011000000000000000000111100101010010011101000000001011100001001001001110000000010101011111011111110100000000000101000000110000000000000001011001001010100110000000000000000000110001000101000000000111111100110011011110000000001000001001111110111010000000010111010011100100101100000000101110101110010010010000000001011101011010100011000000000010000010110110101000100000000111111101011100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
}

[Fact]
[Category("QRGenerator/TextEncoding")]
public void trim_leading_zeros_works()
{
var gen = new QRCodeGenerator();
var qrData = gen.CreateQrCode("this is a test", QRCodeGenerator.ECCLevel.M);
var result = string.Join("", qrData.ModuleMatrix.Select(x => x.ToBitString()).ToArray());
result.ShouldBe("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111001101011111110000000010000010010000100000100000000101110101101101011101000000001011101010001010111010000000010111010101010101110100000000100000101010101000001000000001111111010101011111110000000000000000110010000000000000000101111100011101111100000000001110100011110001100010000000001100011010110010011000000000100111000011010011100000000001001011001101011000100000000000000000100100001001100000000111111100111110001110000000001000001010011000011010000000010111010101110111101100000000101110101000000110100000000001011101011111000010000000000010000010010011010010000000000111111101101111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
}

[Fact]
[Category("QRGenerator/TextEncoding")]
public void isValidIso_works()
Expand Down

0 comments on commit 276e4ec

Please sign in to comment.