File tree 3 files changed +31
-2
lines changed
3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -463,6 +463,13 @@ impl<'a> SourceCollector<'a> {
463
463
} ;
464
464
let contents = str:: from_utf8_owned ( contents) . unwrap ( ) ;
465
465
466
+ // Remove the utf-8 BOM if any
467
+ let contents = if contents. starts_with ( "\ufeff " ) {
468
+ contents. as_slice ( ) . slice_from ( 3 )
469
+ } else {
470
+ contents. as_slice ( )
471
+ } ;
472
+
466
473
// Create the intermediate directories
467
474
let mut cur = self . dst . clone ( ) ;
468
475
let mut root_path = ~"../../";
@@ -482,7 +489,7 @@ impl<'a> SourceCollector<'a> {
482
489
root_path : root_path,
483
490
} ;
484
491
try!( layout:: render ( & mut w as & mut Writer , & self . cx . layout ,
485
- & page, & ( "" ) , & Source ( contents. as_slice ( ) ) ) ) ;
492
+ & page, & ( "" ) , & Source ( contents) ) ) ;
486
493
try!( w. flush ( ) ) ;
487
494
return Ok ( ( ) ) ;
488
495
}
Original file line number Diff line number Diff line change @@ -271,13 +271,22 @@ impl CodeMap {
271
271
}
272
272
}
273
273
274
- pub fn new_filemap ( & self , filename : FileName , mut src : ~str ) -> Rc < FileMap > {
274
+ pub fn new_filemap ( & self , filename : FileName , src : ~str ) -> Rc < FileMap > {
275
275
let mut files = self . files . borrow_mut ( ) ;
276
276
let start_pos = match files. get ( ) . last ( ) {
277
277
None => 0 ,
278
278
Some ( last) => last. deref ( ) . start_pos . to_uint ( ) + last. deref ( ) . src . len ( ) ,
279
279
} ;
280
280
281
+ // Remove utf-8 BOM if any.
282
+ // FIXME #12884: no efficient/safe way to remove from the start of a string
283
+ // and reuse the allocation.
284
+ let mut src = if src. starts_with ( "\ufeff " ) {
285
+ src. as_slice ( ) . slice_from ( 3 ) . into_owned ( )
286
+ } else {
287
+ src
288
+ } ;
289
+
281
290
// Append '\n' in case it's not already there.
282
291
// This is a workaround to prevent CodeMap.lookup_filemap_idx from accidentally
283
292
// overflowing into the next filemap in case the last byte of span is also the last
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // This file has utf-8 BOM, it should be compiled normally without error.
12
+
13
+ pub fn main ( ) { }
You can’t perform that action at this time.
0 commit comments