Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [

[workspace.package]
version = "25.3.0"
rust-version = "1.84.0"
rust-version = "1.91.0"
Comment thread
leighmcculloch marked this conversation as resolved.

[workspace.dependencies]
soroban-sdk = { version = "25.3.0", path = "soroban-sdk" }
Expand Down
34 changes: 29 additions & 5 deletions soroban-sdk-macros/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,33 @@ pub fn docs_from_attrs(attrs: &[Attribute]) -> StringM<DOCS_MAX_LEN> {
_ => None,
})
.map(|s| s.trim().to_string())
.join("\n")
.as_bytes()
.to_vec();
docs.truncate(DOCS_MAX_LEN as usize);
docs.try_into().unwrap()
.join("\n");
// Truncate on a char boundary to avoid splitting multi-byte UTF-8 codepoints.
let max = DOCS_MAX_LEN as usize;
let safe_len = docs.floor_char_boundary(max);
docs.truncate(safe_len);
docs.into_bytes().try_into().unwrap()
}

#[cfg(test)]
mod test {
use super::*;
use syn::parse_quote;

#[test]
fn test_truncation_does_not_split_multibyte_utf8() {
// (DOCS_MAX_LEN - 1) ASCII bytes followed by 'é' (2 bytes: 0xC3
// 0xA9) = DOCS_MAX_LEN + 1 bytes. Truncation at DOCS_MAX_LEN keeps
// the 0xC3 but drops the 0xA9, producing invalid UTF-8.
let padding = "a".repeat(DOCS_MAX_LEN as usize - 1);
let doc_value = format!("{padding}é");
let attr: Attribute = parse_quote!(#[doc = #doc_value]);
let result = docs_from_attrs(&[attr]);
let bytes: Vec<u8> = result.into();
assert!(
std::str::from_utf8(&bytes).is_ok(),
"truncation produced invalid UTF-8: trailing bytes {:?}",
&bytes[bytes.len().saturating_sub(4)..]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"val": {
"contract_instance": {
"executable": {
"wasm": "bace965b8cb8356bcb9ec67b78828f9f39379aa8be62c7a9982ce93c7d13eea4"
"wasm": "8d628a321427edfff529b77997d15aaf6427664924d3173956c78abc76c0ca54"
},
"storage": null
}
Expand All @@ -68,11 +68,11 @@
"ext": "v0",
"cost_inputs": {
"ext": "v0",
"n_instructions": 838,
"n_functions": 9,
"n_instructions": 801,
"n_functions": 8,
"n_globals": 4,
"n_table_entries": 0,
"n_types": 9,
"n_types": 8,
"n_data_segments": 1,
"n_elem_segments": 0,
"n_imports": 7,
Expand All @@ -81,8 +81,8 @@
}
}
},
"hash": "bace965b8cb8356bcb9ec67b78828f9f39379aa8be62c7a9982ce93c7d13eea4",
"code": "0061736d0100000001320960017e017e60037e7e7e017e60047e7e7e7e017e60027e7e017e60027f7e0060027f7f0060027f7f017f60000060017f00022b070176013300000162016d0001016d01610002017601680001016901320000017601310003016901310000030a0904050604050703080705030100110621047f01418080c0000b7f0041cc80c0000b7f0041cc80c0000b7f0041d080c0000b072f05066d656d6f7279020003616464000d015f03010a5f5f646174615f656e6403020b5f5f686561705f6261736503030aa80e09d00604017f017e027f017e23808080800041c0006b220224808080800002400240024002400240200142ff018342cb00520d00200110808080800021032002410036021020022001370308200220034220883e0214200241186a200241086a1088808080000240200229031822014202510d002001a74101710d00024020022903202201a741ff0171220441ca00460d002004410e470d010b02400240024002402001419080c08000ad4220864204844284808080c000108180808000422088a70e0400010203060b200228021020022802141089808080000d05410021050c060b2002280210200228021410898080800041014b0d04200241186a200241086a108880808000200229031822014202510d042001a74101710d0420022903202101410021040240034020044118460d01200241186a20046a4202370300200441086a21040c000b0b200142ff018342cc00520d04200141b480c08000ad422086420484200241186aad4220864204844284808080301082808080001a200241306a2002290318108a8080800020022802300d0420022903382103200241306a2002290320108a8080800020022802300d042002290328220642ff018342cb00520d0420022903382101410121050c050b2002280210200228021410898080800041014b0d03200241186a200241086a108880808000200229031822014202510d032001a74101710d032002290320220142ff01834204520d03410a410f41092001422088a72204410f461b2004410a461b22044109460d03410221050c050b2002280210200228021410898080800041014b0d02200241186a200241086a108880808000200229031822014202510d022001a74101710d022002290320220142ff018342cb00520d02410021040240034020044110460d01200241306a20046a4202370300200441086a21040c000b0b2001200241306aad4220864204844284808080201083808080001a200241186a2002290330108a8080800020022802180d022002290338220142ff018342cb00520d0220022903202103410321050c030b200041043a00000c040b200041043a00000c030b200041043a00000c020b0b200020063703182000200137031020002003370308200020043a0001200020053a00000b200241c0006a2480808080000b4a02017e017f42022102024020012802082203200128020c4f0d00200020012903002003ad4220864204841085808080003703082001200341016a360208420021020b200020023703000b1900024020012000490d00200120006b0f0b108c80808000000b5d02017f017e024002402001a741ff0171220241c100460d00024020024107460d00420121034283908080800121010c020b20014208872101420021030c010b42002103200110848080800021010b20002003370300200020013703080b910102027f017e23808080800041106b22022480808080000240024020012802082203200128020c490d00200042023703000c010b200220012903002003ad422086420484108580808000108a808080000240200341016a2203450d00200229030021042000200229030837030820002004370300200120033602080c010b108c80808000000b200241106a2480808080000b0900108f80808000000be50404027f027e017f057e23808080800041c0006b2202248080808000200241086a2000108780808000024002400240024020022d000822034104460d00200229031821002002290310210420023100092105200241086a200110878080800020022d000822064104460d002002290318210720022903102108200231000921094200210a4200210b024002400240024020030e0406020100060b200010808080800021012002410036023020022000370328200220014220883e0234420021000340200241086a200241286a108b80808000200229030822014202510d032001a74101710d0520022903102201420053200020017c2201200053470d07200121000c000b0b2005210b0c040b2000420053200420007c220b20045373450d030c040b2000420053200420007c220b20045373450d020c030b000b200241386a108e80808000000b02400240024002400240024020060e0405020100050b200710808080800021002002410036023020022007370328200220004220883e0234420021000340200241086a200241286a108b80808000200229030822014202510d032001a74101710d0420022903102201420053200020017c2201200053470d06200121000c000b0b2009210a0c030b2007420053200820077c220a200853730d030c020b2000420053200820007c220a200853730d020c010b200241386a108e80808000000b200a420053200b200a7c2200200b53730d000240024020004280808080808080c0007c42ffffffffffffffff00560d00200042088642078421000c010b200010868080800021000b200241c0006a24808080800020000f0b108c80808000000b0900108f80808000000b0300000b0b550100418080c0000b4c556474415564744255647443556474440000100004000000040010000400000008001000040000000c001000040000006162630030001000010000003100100001000000320010000100000000cf030e636f6e747261637473706563763000000003000000000000000000000008556474456e756d32000000020000000000000001410000000000000a0000000000000001420000000000000f00000002000000000000000000000007556474456e756d0000000004000000000000000000000004556474410000000100000000000000045564744200000001000007d0000000095564745374727563740000000000000100000000000000045564744300000001000007d000000008556474456e756d320000000100000000000000045564744400000001000007d0000000085564745475706c65000000010000000000000000000000085564745475706c650000000200000000000000013000000000000007000000000000000131000000000003ea0000000700000001000000000000000000000009556474537472756374000000000000030000000000000001610000000000000700000000000000016200000000000007000000000000000163000000000003ea000000070000000000000000000000036164640000000002000000000000000161000000000007d000000007556474456e756d00000000000000000162000000000007d000000007556474456e756d000000000100000007001e11636f6e7472616374656e766d6574617630000000000000001900000000002b0e636f6e74726163746d65746176300000000000000005727376657200000000000006312e38342e300000"
"hash": "8d628a321427edfff529b77997d15aaf6427664924d3173956c78abc76c0ca54",
"code": "0061736d01000000012e0860017e017e60037e7e7e017e60047e7e7e7e017e60027e7e017e60027f7e0060027f7f0060027f7f017f600000022b070176013300000162016d0001016d01610002017601680001016901320000017601310003016901310000030908040506040503070705030100110621047f01418080c0000b7f0041cc80c0000b7f0041cc80c0000b7f0041d080c0000b072f05066d656d6f7279020003616464000c015f03010a5f5f646174615f656e6403020b5f5f686561705f6261736503030ad90d08d30604017f017e027f017e23808080800041c0006b220224808080800002400240200142ff018342cb00510d00200041043a00000c010b200110808080800021032002410036021020022001370308200220034220883e0214200241186a200241086a1088808080000240024002400240200229031822014202510d002001a74101710d00024020022903202201a741ff0171220441ca00460d002004410e470d010b02400240024002402001419080c08000ad4220864204844284808080c000108180808000422088a70e0400010203050b200228021020022802141089808080000d04410021050c050b2002280210200228021410898080800041014b0d03200241186a200241086a108880808000200229031822014202510d032001a74101710d0320022903202101410021040240034020044118460d01200241186a20046a4202370300200441086a21040c000b0b200142ff018342cc00520d03200141b480c08000ad422086420484200241186aad4220864204844284808080301082808080001a200241306a2002290318108a8080800020022802300d0320022903382103200241306a2002290320108a8080800020022802300d032002290328220642ff018342cb00520d0320022903382101410121050c040b2002280210200228021410898080800041014b0d02200241186a200241086a108880808000200229031822014202510d022001a74101710d022002290320220142ff01834204520d02410a410f41092001422088a72204410f461b2004410a461b22044109460d02410221050c040b2002280210200228021410898080800041014b0d01200241186a200241086a108880808000200229031822014202510d012001a74101710d012002290320220142ff018342cb00520d01410021040240034020044110460d01200241306a20046a4202370300200441086a21040c000b0b2001200241306aad4220864204844284808080201083808080001a200241186a2002290330108a8080800020022802184101460d012002290338220142ff018342cb00520d0120022903202103410321050c020b200041043a00000c030b200041043a00000c020b0b200020063703182000200137031020002003370308200020043a0001200020053a00000b200241c0006a2480808080000b4a02017e017f42022102024020012802082203200128020c4f0d00200020012903002003ad4220864204841085808080003703082001200341016a360208420021020b200020023703000b1900024020012000490d00200120006b0f0b108d80808000000b5d02017f017e024002402001a741ff0171220241c100460d00024020024107460d00420121034283908080800121010c020b20014208872101420021030c010b42002103200110848080800021010b20002003370300200020013703080b7803017f017e017f23808080800041106b220224808080800042022103024020012802082204200128020c4f0d00200220012903002004ad422086420484108580808000108a8080800020022903002103200020022903083703082001200441016a3602080b20002003370300200241106a2480808080000bb70404027f027e017f057e23808080800041306b22022480808080002002200010878080800002400240024020022d000022034104460d002002290310210020022903082104200231000121052002200110878080800020022d000022064104460d002002290310210720022903082108200231000121094200210a4200210b024002400240024020030e0405020100050b200010808080800021012002410036022820022000370320200220014220883e022c4200210003402002200241206a108b80808000200229030022014202510d032001a74101710d0620022903082201420053200020017c2201200053470d06200121000c000b0b2005210b0c030b2000420053200420007c220b20045373450d020c030b2000420053200420007c220b20045373450d010c020b000b0240024002400240024020060e0404020100040b200710808080800021002002410036022820022007370320200220004220883e022c4200210003402002200241206a108b80808000200229030022014202510d032001a74101710d0520022903082201420053200020017c2201200053470d05200121000c000b0b2009210a0c020b2007420053200820077c220a200853730d020c010b2000420053200820007c220a200853730d010b200a420053200b200a7c2200200b53730d000240024020004280808080808080c0007c42ffffffffffffffff00560d00200042088642078421000c010b200010868080800021000b200241306a24808080800020000f0b108d80808000000b0900108e80808000000b0300000b0b550100418080c0000b4c556474415564744255647443556474440000100004000000040010000400000008001000040000000c001000040000006162630030001000010000003100100001000000320010000100000000cf030e636f6e74726163747370656376300000000000000000000000036164640000000002000000000000000161000000000007d000000007556474456e756d00000000000000000162000000000007d000000007556474456e756d00000000010000000700000002000000000000000000000007556474456e756d0000000004000000000000000000000004556474410000000100000000000000045564744200000001000007d0000000095564745374727563740000000000000100000000000000045564744300000001000007d000000008556474456e756d320000000100000000000000045564744400000001000007d0000000085564745475706c6500000003000000000000000000000008556474456e756d32000000020000000000000001410000000000000a0000000000000001420000000000000f000000010000000000000000000000085564745475706c650000000200000000000000013000000000000007000000000000000131000000000003ea0000000700000001000000000000000000000009556474537472756374000000000000030000000000000001610000000000000700000000000000016200000000000007000000000000000163000000000003ea00000007001e11636f6e7472616374656e766d6574617630000000000000001900000000002b0e636f6e74726163746d65746176300000000000000005727376657200000000000006312e39312e300000"
}
},
"ext": "v0"
Expand Down
Loading
Loading