fix issue encoding qrcode digit only data

This commit is contained in:
Henry Schimke
2023-01-07 14:40:31 -06:00
parent 245e14085a
commit 0824d3547a
3 changed files with 13 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "rxing"
version = "0.2.7"
version = "0.2.8"
description="A rust port of the zxing barcode library."
license="Apache-2.0"
repository="https://github.com/hschimke/rxing"

View File

@@ -71,6 +71,17 @@ fn testGetAlphanumericCode() {
assert_eq!(-1, encoder::getAlphanumericCode(b'\0' as u32));
}
#[test]
fn test_digits_only() {
let test_data = "374833744734397449";
let data = encoder::encode(test_data, ErrorCorrectionLevel::H).expect("encode");
let decode = crate::qrcode::decoder::decoder::decode_bitmatrix(
&data.getMatrix().as_ref().unwrap().clone().into(),
)
.expect("decode");
assert_eq!(test_data, decode.getText());
}
#[test]
fn testChooseMode() {
// Numeric Mode::

View File

@@ -732,7 +732,7 @@ pub fn appendNumericBytes(content: &str, bits: &mut BitArray) -> Result<(), Exce
// Encode three numeric letters in ten bits.
let num2 = content.chars().nth(i + 1).unwrap() as u8 - b'0';
let num3 = content.chars().nth(i + 2).unwrap() as u8 - b'0';
bits.appendBits((num1 * 100 + num2 * 10 + num3) as u32, 10)?;
bits.appendBits(num1 as u32 * 100 + num2 as u32 * 10 + num3 as u32, 10)?;
i += 3;
} else if i + 1 < length {
// Encode two numeric letters in seven bits.