File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,10 @@ fn load_chapter<P: AsRef<Path>>(
264
264
format ! ( "Unable to read \" {}\" ({})" , link. name, location. display( ) )
265
265
} ) ?;
266
266
267
+ if content. as_bytes ( ) . starts_with ( b"\xef \xbb \xbf " ) {
268
+ content. replace_range ( ..3 , "" ) ;
269
+ }
270
+
267
271
let stripped = location
268
272
. strip_prefix ( & src_dir)
269
273
. expect ( "Chapters are always inside a book" ) ;
@@ -393,6 +397,29 @@ And here is some \
393
397
assert_eq ! ( got, should_be) ;
394
398
}
395
399
400
+ #[ test]
401
+ fn load_a_single_chapter_with_utf8_bom_from_disk ( ) {
402
+ let temp_dir = TempFileBuilder :: new ( ) . prefix ( "book" ) . tempdir ( ) . unwrap ( ) ;
403
+
404
+ let chapter_path = temp_dir. path ( ) . join ( "chapter_1.md" ) ;
405
+ File :: create ( & chapter_path)
406
+ . unwrap ( )
407
+ . write_all ( ( "\u{feff} " . to_owned ( ) + DUMMY_SRC ) . as_bytes ( ) )
408
+ . unwrap ( ) ;
409
+
410
+ let link = Link :: new ( "Chapter 1" , chapter_path) ;
411
+
412
+ let should_be = Chapter :: new (
413
+ "Chapter 1" ,
414
+ DUMMY_SRC . to_string ( ) ,
415
+ "chapter_1.md" ,
416
+ Vec :: new ( ) ,
417
+ ) ;
418
+
419
+ let got = load_chapter ( & link, temp_dir. path ( ) , Vec :: new ( ) ) . unwrap ( ) ;
420
+ assert_eq ! ( got, should_be) ;
421
+ }
422
+
396
423
#[ test]
397
424
fn cant_load_a_nonexistent_chapter ( ) {
398
425
let link = Link :: new ( "Chapter 1" , "/foo/bar/baz.md" ) ;
You can’t perform that action at this time.
0 commit comments