1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-18 18:51:49 +01:00

actix-router: fix from_hex error (#196)

This commit is contained in:
nujz 2020-09-21 01:04:18 +08:00 committed by GitHub
parent 98a2197a09
commit e5ca271764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# Changes
## Unreleased - 2020-xx-xx
* Fix `from_hex()` method
## [0.2.4] - 2019-12-31
* Add `ResourceDef::resource_path_named()` path generation method

View File

@ -186,7 +186,7 @@ fn from_hex(v: u8) -> Option<u8> {
Some(v - 0x30) // ord('0') == 0x30
} else if v >= b'A' && v <= b'F' {
Some(v - 0x41 + 10) // ord('A') == 0x41
} else if v > b'a' && v <= b'f' {
} else if v >= b'a' && v <= b'f' {
Some(v - 0x61 + 10) // ord('a') == 0x61
} else {
None
@ -225,4 +225,25 @@ mod tests {
assert!(re.match_path(&mut path));
assert_eq!(path.get("id").unwrap(), "qwe%rty");
}
#[test]
fn test_from_hex() {
let hex = b"0123456789abcdefABCDEF";
for i in 0..256 {
let c = i as u8;
if hex.contains(&c) {
assert!(from_hex(c).is_some())
} else {
assert!(from_hex(c).is_none())
}
}
let expected = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15,
];
for i in 0..hex.len() {
assert_eq!(from_hex(hex[i]).unwrap(), expected[i]);
}
}
}