Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip the BOM from the source string if it is present #192

Merged
merged 3 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading