This repository was archived by the owner on Nov 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## 0.3.2 - 2024-10-23
4+
5+ - Fix ` SmolStrBuilder::push ` incorrectly padding null bytes when spilling onto the heap on a
6+ multibyte character push
7+
38## 0.3.1 - 2024-09-04
49
510- Fix ` SmolStrBuilder ` leaking implementation details
Original file line number Diff line number Diff line change @@ -763,7 +763,7 @@ impl SmolStrBuilder {
763763 let mut heap = String :: with_capacity ( new_len) ;
764764 // copy existing inline bytes over to the heap
765765 // SAFETY: inline data is guaranteed to be valid utf8 for `old_len` bytes
766- unsafe { heap. as_mut_vec ( ) . extend_from_slice ( buf) } ;
766+ unsafe { heap. as_mut_vec ( ) . extend_from_slice ( & buf[ .. * len ] ) } ;
767767 heap. push ( c) ;
768768 self . 0 = SmolStrBuilderRepr :: Heap ( heap) ;
769769 }
Original file line number Diff line number Diff line change @@ -255,6 +255,7 @@ fn test_to_smolstr() {
255255 assert_eq ! ( a, smol_str:: format_smolstr!( "{}" , a) ) ;
256256 }
257257}
258+
258259#[ test]
259260fn test_builder_push_str ( ) {
260261 //empty
@@ -290,6 +291,14 @@ fn test_builder_push_str() {
290291 let s = builder. finish ( ) ;
291292 assert ! ( s. is_heap_allocated( ) ) ;
292293 assert_eq ! ( "a" . repeat( 46 ) , s) ;
294+
295+ // heap push on multibyte char
296+ let mut builder = SmolStrBuilder :: new ( ) ;
297+ builder. push_str ( "ohnonononononononono!" ) ;
298+ builder. push ( '🤯' ) ;
299+ let s = builder. finish ( ) ;
300+ assert ! ( s. is_heap_allocated( ) ) ;
301+ assert_eq ! ( "ohnonononononononono!🤯" , s) ;
293302}
294303
295304#[ test]
You can’t perform that action at this time.
0 commit comments