Skip to content

Commit

Permalink
Merge pull request #10 from ionite34/char-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ionite34 authored Sep 26, 2022
2 parents b45dc12 + 689cb75 commit a47903a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ pub fn decode(string: &str) -> Result<Vec<u8>, String> {
// last character and it's NOT a tail character.
residue = (residue + 11) % 8;

// Char must be within the table size (4340)
if c as usize > 4339 {
return Err(format!("Invalid character {i}: [{c:?}]"));
}

let (n_new_bits, new_bits) = match c {
// Check if the character is in the zero set
c if ZERO_SET.contains(&(c as u16)) => {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_base2048.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_b2048_encode() -> None:
"ետћζы༎Z",
"Unexpected character 6: ['Z'] after termination sequence 5: ['༎']",
),
("ϓțƘ🤔", "Invalid character 3: ['🤔']"),
(chr(4340), "Invalid character 0: ['ჴ']"),
],
)
def test_b2048_decode_err(data: str, expected: str) -> None:
Expand Down

0 comments on commit a47903a

Please sign in to comment.