Fix formatter discarding nul bytes.

This commit is contained in:
KtorZ 2024-03-09 18:59:35 +01:00
parent b761d6a76d
commit d581183cc6
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
4 changed files with 24 additions and 1 deletions

View File

@ -16,6 +16,7 @@
- **aikup**: error message when version is not found. @rvcas
- **aiken**: support outputting mainnet addresses for validators. @rvcas
- **aiken-lang**: added serde to CheckedModule to encode modules as cbor. @rvcas
- **aiken-lang**: Strings can contain a nul byte using the escape sequence `\0`. @KtorZ
### Fixed
@ -32,7 +33,7 @@
- **aiken-lang**: disallow `MLResult` in a type definition. @rvcas
- **aiken-lang**: reversed deserialization of bls types out of data types. @rvcas
- **aiken-lang**: validator args unexpectedly unbound causing code gen crashes. @rvcas
- **aiken-lang**: allow implicitly discarded values when right-hand-side unified with `Void`. @KtorZ
- **aiken-lang**: allow implicitly discarded values when right-hand side unified with `Void`. @KtorZ
### Changed

View File

@ -2138,6 +2138,7 @@ fn escape(string: &str) -> String {
'\n' => vec!['\\', 'n'],
'\r' => vec!['\\', 'r'],
'\t' => vec!['\\', 't'],
'\0' => vec!['\\', '0'],
'"' => vec!['\\', c],
'\\' => vec!['\\', c],
_ => vec![c],

View File

@ -20,6 +20,18 @@ fn format_simple_module() {
);
}
#[test]
fn format_nul_byte() {
assert_format!(
r#"
fn label(str: String) -> Void {
str
|> builtin.append_string(@"\0", _)
|> builtin.debug(Void)
}"#
);
}
#[test]
fn format_g1_element_constant() {
assert_format!(

View File

@ -0,0 +1,9 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn label(str: String) -> Void {\n str\n |> builtin.append_string(@\"\\0\", _)\n |> builtin.debug(Void)\n}"
---
fn label(str: String) -> Void {
str
|> builtin.append_string(@"\0", _)
|> builtin.debug(Void)
}