Skip to content

Commit

Permalink
Merge pull request #192 from JoshLee0915/utf-bom-check
Browse files Browse the repository at this point in the history
Strip the BOM from the source string if it is present
  • Loading branch information
janhohenheim authored May 17, 2024
2 parents 9d596d1 + 165eda8 commit 49cc1a2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/compiler/src/compiler/run_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ pub(crate) fn compile(compiler: &Compiler) -> Result<Compilation> {
let chars: Vec<Vec<u32>> = compiler
.files
.iter()
.map(|file| file.source.chars().map(|c| c as u32).collect())
.map(|file| {
// Strip the BOM from the source string if it is present before compiling.
// Rust does not do this by default
// https://github.com/rust-lang/rfcs/issues/2428
let source = match file.source.strip_prefix('\u{feff}') {
None => file.source.as_str(),
Some(sanitized_string) => sanitized_string,
};
source.chars().map(|c| c as u32).collect()
})
.collect();
let chars: Vec<_> = chars.iter().map(|c| c.as_slice()).collect();
let initial = CompilationIntermediate::from_job(compiler, chars);
Expand Down

0 comments on commit 49cc1a2

Please sign in to comment.