Emit warning when detecting an hex string interpreted as UTF-8 bytes.

This will probably save people minutes/hours of puzzled debugging. This is only a warning because there may be cases where one do actually want to specify an hex-encoded bytearray. In which case, they can get rid of the warning by using the plain bytearray syntax (i.e. as an array of bytes).
This commit is contained in:
KtorZ
2023-02-18 11:36:45 +01:00
parent d72e13c7c8
commit 78770d14b7
3 changed files with 74 additions and 15 deletions

View File

@@ -305,3 +305,17 @@ fn trace_if_false_ko() {
Err((_, Error::CouldNotUnify { .. }))
))
}
#[test]
fn utf8_hex_literal_warning() {
let source_code = r#"
pub const policy_id = "f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535"
"#;
let (warnings, _) = check(parse(source_code)).unwrap();
assert!(matches!(
warnings[0],
Warning::Utf8ByteArrayIsValidHexString { .. }
))
}