File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
22
- Missing ` winapi ` keyword.
23
23
- Erroneous removal of BOM.
24
24
- Erroneous transcoding of UTF-16 input to UTF-8.
25
+ - Unwanted use of the replacement character when encoding. This now results in an error.
25
26
26
27
## [ 0.2.0] - 2024-05-07
27
28
Original file line number Diff line number Diff line change @@ -191,7 +191,18 @@ impl FileFormatter {
191
191
fn encode < ' a > ( encoding : & ' static Encoding , data : & ' a str ) -> io:: Result < Cow < ' a , [ u8 ] > > {
192
192
// encoding_rs doesn't support encoding to UTF16, so we do it ourselves.
193
193
if encoding. output_encoding ( ) == encoding {
194
- Ok ( encoding. encode ( data) . 0 )
194
+ let ( encoded_data, _encoding_used, replacements) = encoding. encode ( data) ;
195
+ if replacements {
196
+ Err ( io:: Error :: new (
197
+ io:: ErrorKind :: InvalidData ,
198
+ format ! (
199
+ "Formatting result contains data that cannot be encoded as {}" ,
200
+ encoding. name( )
201
+ ) ,
202
+ ) )
203
+ } else {
204
+ Ok ( encoded_data)
205
+ }
195
206
} else if encoding == encoding_rs:: UTF_16BE {
196
207
Ok ( Cow :: Owned ( Self :: encode_utf16be ( data) ) )
197
208
} else if encoding == encoding_rs:: UTF_16LE {
You can’t perform that action at this time.
0 commit comments