Skip to content

Commit f810607

Browse files
committed
Route yarn block and stanza BOMs through split_bom
#1057 added formats/yarn/blocks.rs and stanzas.rs with their own leading-BOM splits, which the new guard rejects once main is merged. Both now call formats::text::split_bom, whose BOM half is now &'static str (it is always "" or U+FEFF) so callers can store it. No behavior change. Assisted-by: Claude Code:claude-opus-5-5
1 parent 41c332c commit f810607

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎crates/socket-patch-core/src/formats/text.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
/// `(bom, rest)`: a leading UTF-8 BOM split off (`""` when there is none),
1414
/// so an edit can read `rest` and restore `bom` byte-exact on write.
15-
pub fn split_bom(text: &str) -> (&str, &str) {
15+
pub fn split_bom(text: &str) -> (&'static str, &str) {
1616
match text.strip_prefix('\u{feff}') {
1717
Some(rest) => ("\u{feff}", rest),
1818
None => ("", text),

‎crates/socket-patch-core/src/formats/yarn/blocks.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! apart on what a block, a key or a field is.
88
99
use super::patterns::{berry_npm_alias_target, split_berry_key_patterns, split_pattern};
10+
use crate::formats::text::split_bom;
1011
use crate::vendor::common::detect_eol;
1112

1213
/// One key-line block of a yarn lockfile (classic or berry).
@@ -42,10 +43,9 @@ pub(crate) fn scan_blocks(text: &str) -> Vec<LockBlock> {
4243
}
4344
let mut content = content.strip_suffix('\r').unwrap_or(content);
4445
if start == 0 {
45-
if let Some(rest) = content.strip_prefix('\u{feff}') {
46-
start = '\u{feff}'.len_utf8();
47-
content = rest;
48-
}
46+
let (bom, rest) = split_bom(content);
47+
start = bom.len();
48+
content = rest;
4949
}
5050
lines.push((start, pos, content, terminated));
5151
}

‎crates/socket-patch-core/src/formats/yarn/stanzas.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
use std::borrow::Cow;
1515

16+
use crate::formats::text::split_bom;
1617
use crate::utils::line_endings::{to_lf, LineEndings};
1718

1819
/// A berry lock split into its stanzas (see the module docs).
@@ -31,10 +32,7 @@ impl BerryStanzas {
3132
/// Split `raw`. A [`LineEndings::Mixed`] lock must be refused by the
3233
/// caller first; one would be rendered back in a single style.
3334
pub(crate) fn parse(raw: &str) -> Self {
34-
let (bom, body) = match raw.strip_prefix('\u{feff}') {
35-
Some(rest) => ("\u{feff}", rest),
36-
None => ("", raw),
37-
};
35+
let (bom, body) = split_bom(raw);
3836
let eol = LineEndings::of(body);
3937
let lf = to_lf(body).into_owned();
4038
let trimmed = lf.trim_end_matches('\n');

0 commit comments

Comments
 (0)