Skip to content

Commit e75c274

Browse files
Wire vendored nuget.config through formats::nuget (#594) (#1288)
* Start refactor for #594 Assisted-by: Claude Code:claude-opus-5-5 * Wire vendored nuget.config via formats::nuget Vendored NuGet now reads the source keys and finds the <packageSources>, <packageSourceMapping> and <configuration> anchors through formats::nuget::parse_config, the reader that hosted, upstream restore and VEX already use. The private substring scanner (blank_comments, parse_config_source_keys, attr_value, self_closing_package_sources, insert_at_line) is deleted. User impact: - A close tag written with whitespace (</packageSources >) is now the section that gets extended; vendor used to append a second section NuGet ignores, so restore failed NU1100/NU1403 (#685). - An empty <packageSourceMapping /> is expanded in place instead of left beside a second mapping section. - A section opened and closed on one line receives the source inside it, not before its open tag. - Catch-all keys are written XML-encoded, so a key with & or a quote keeps its identity. - Malformed XML or a repeated section is refused with "malformed XML or a repeated section; not wired" instead of being spliced at the first substring match, as hosted already does. Output bytes for well-formed configs are unchanged. Fixes #685 Refs #594 Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 278d93e commit e75c274

2 files changed

Lines changed: 335 additions & 208 deletions

File tree

‎crates/socket-patch-core/src/formats/nuget/mod.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ fn decode_entities(raw: &str) -> String {
291291
out
292292
}
293293

294+
/// Encode `value` for a double-quoted attribute: the inverse of
295+
/// [`parse_config`]'s decoding, so a key read as `a&b` is written back as
296+
/// `a&amp;b` and keeps its identity.
297+
pub(crate) fn xml_attribute(value: &str) -> String {
298+
value
299+
.replace('&', "&amp;")
300+
.replace('"', "&quot;")
301+
.replace('<', "&lt;")
302+
// Literal XML attribute whitespace would be normalized to spaces.
303+
.replace('\t', "&#x9;")
304+
.replace('\n', "&#xA;")
305+
.replace('\r', "&#xD;")
306+
}
307+
294308
#[cfg(test)]
295309
mod tests {
296310
#[test]

0 commit comments

Comments
 (0)