mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #28032 - andreubotella:document-charset-bom-cleanup, r=jdm
Clean up the code to BOM sniff. See https://github.com/servo/servo/pull/28006#discussion_r551968553 cc @CYBAI <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because they don't change any behavior. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
3de36aa286
1 changed files with 5 additions and 15 deletions
|
@ -487,28 +487,18 @@ impl ServoParser {
|
|||
// encoding based on the BOM, but it won't change
|
||||
// `self.document.encoding` in the process.
|
||||
{
|
||||
let set_bom_to_none = if let Some(partial_bom) = self.bom_sniff.borrow_mut().as_mut() {
|
||||
let mut bom_sniff = self.bom_sniff.borrow_mut();
|
||||
if let Some(partial_bom) = bom_sniff.as_mut() {
|
||||
if partial_bom.len() + chunk.len() >= 3 {
|
||||
partial_bom.extend(chunk.iter().take(3 - partial_bom.len()).copied());
|
||||
//println!("Full BOM: {:?}", partial_bom);
|
||||
if let Some((encoding, _)) = Encoding::for_bom(&partial_bom) {
|
||||
//println!("Encoding: {}", encoding.name());
|
||||
self.document.set_encoding(encoding);
|
||||
} else {
|
||||
//println!("Bytes are not a BOM.");
|
||||
};
|
||||
true
|
||||
}
|
||||
drop(bom_sniff);
|
||||
*self.bom_sniff.borrow_mut() = None;
|
||||
} else {
|
||||
partial_bom.extend(chunk.iter().copied());
|
||||
//println!("Partial BOM: {:?}", partial_bom);
|
||||
false
|
||||
}
|
||||
} else {
|
||||
//println!("partial_bom is None");
|
||||
false
|
||||
};
|
||||
if set_bom_to_none {
|
||||
*self.bom_sniff.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue