From dfe433ea46a114c9ee2a066ec1edf247a2ce31f2 Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 31 Aug 2023 18:22:09 -0400 Subject: [PATCH] fix: trim whitespace when loading hex strings from files closes #720 --- CHANGELOG.md | 1 + crates/aiken/src/cmd/uplc/decode.rs | 2 +- crates/aiken/src/cmd/uplc/eval.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1cc387..e67944c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- **uplc**: trim whitespace when loading files with hex strings to avoid confusing errors #720 - **uplc**: uplc `Constant::Data` formatting - **aiken-lang**: empty records properly parse as record sugar - **aiken-project**: when a module name has a hyphen we should behave like rust and force an underscore diff --git a/crates/aiken/src/cmd/uplc/decode.rs b/crates/aiken/src/cmd/uplc/decode.rs index ac8036dc..c6eb74d3 100644 --- a/crates/aiken/src/cmd/uplc/decode.rs +++ b/crates/aiken/src/cmd/uplc/decode.rs @@ -34,7 +34,7 @@ pub fn exec( let bytes = if hex { let hex_bytes = std::fs::read_to_string(&input).into_diagnostic()?; - hex::decode(hex_bytes).into_diagnostic()? + hex::decode(hex_bytes.trim()).into_diagnostic()? } else { std::fs::read(&input).into_diagnostic()? }; diff --git a/crates/aiken/src/cmd/uplc/eval.rs b/crates/aiken/src/cmd/uplc/eval.rs index cdddd935..5b70d166 100644 --- a/crates/aiken/src/cmd/uplc/eval.rs +++ b/crates/aiken/src/cmd/uplc/eval.rs @@ -33,7 +33,7 @@ pub fn exec( let mut program = if cbor { let cbor_hex = std::fs::read_to_string(&script).into_diagnostic()?; - let raw_cbor = hex::decode(cbor_hex).into_diagnostic()?; + let raw_cbor = hex::decode(cbor_hex.trim()).into_diagnostic()?; let prog = Program::::from_cbor(&raw_cbor, &mut Vec::new()) .into_diagnostic()?;