Skip to content

Commit 01c3f3b

Browse files
authored
Merge pull request #3 from MaximKitsenko/OneCharStringBugFix
bugfix: string with length 1 throws exception
2 parents 0d35cdc + 631d04e commit 01c3f3b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Source/GenCode128/Code128Content.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private int[] StringToCode128(string asciiData)
3737
var csa1 = asciiBytes.Length > 0
3838
? Code128Code.CodesetAllowedForChar(asciiBytes[0])
3939
: Code128Code.CodeSetAllowed.CodeAorB;
40-
var csa2 = asciiBytes.Length > 0
40+
var csa2 = asciiBytes.Length > 1
4141
? Code128Code.CodesetAllowedForChar(asciiBytes[1])
4242
: Code128Code.CodeSetAllowed.CodeAorB;
4343
var currentCodeSet = this.GetBestStartSet(csa1, csa2);

Source/GenCode128Tests/ContentTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,17 @@ public void FullStringTest()
372372
result = content.Codes;
373373
Assert.AreEqual(10, result.Length, "Wrong number of code values in result");
374374
}
375+
376+
[Test]
377+
public void OneCharStringTest()
378+
{
379+
var content = new Code128Content("0");
380+
var result = content.Codes;
381+
Assert.AreEqual(4, result.Length, "Wrong number of code values in result");
382+
Assert.AreEqual(104, result[0], "Start code wrong");
383+
Assert.AreEqual(16, result[1], "Code value #1 wrong");
384+
Assert.AreEqual(17, result[2], "Checksum wrong");
385+
Assert.AreEqual(106, result[3], "Stop character wrong");
386+
}
375387
}
376388
}

0 commit comments

Comments
 (0)