File tree 3 files changed +15
-1
lines changed
3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
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
+
3
8
## 0.3.1 - 2024-09-04
4
9
5
10
- Fix ` SmolStrBuilder ` leaking implementation details
Original file line number Diff line number Diff line change @@ -763,7 +763,7 @@ impl SmolStrBuilder {
763
763
let mut heap = String :: with_capacity ( new_len) ;
764
764
// copy existing inline bytes over to the heap
765
765
// 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 ] ) } ;
767
767
heap. push ( c) ;
768
768
self . 0 = SmolStrBuilderRepr :: Heap ( heap) ;
769
769
}
Original file line number Diff line number Diff line change @@ -255,6 +255,7 @@ fn test_to_smolstr() {
255
255
assert_eq ! ( a, smol_str:: format_smolstr!( "{}" , a) ) ;
256
256
}
257
257
}
258
+
258
259
#[ test]
259
260
fn test_builder_push_str ( ) {
260
261
//empty
@@ -290,6 +291,14 @@ fn test_builder_push_str() {
290
291
let s = builder. finish ( ) ;
291
292
assert ! ( s. is_heap_allocated( ) ) ;
292
293
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) ;
293
302
}
294
303
295
304
#[ test]
You can’t perform that action at this time.
0 commit comments