diff --git a/crates/uv-workspace/src/pyproject_mut.rs b/crates/uv-workspace/src/pyproject_mut.rs index 696aa442fadd..f24c960cf15e 100644 --- a/crates/uv-workspace/src/pyproject_mut.rs +++ b/crates/uv-workspace/src/pyproject_mut.rs @@ -893,16 +893,14 @@ fn reformat_array_multiline(deps: &mut Array) { let decor_prefix = decor .prefix() .and_then(|s| s.as_str()) - .map(|s| s.split('#').next().unwrap_or("")) - .unwrap_or_default() - .trim_start_matches(['\r', '\n'].as_ref()) - .to_string(); + .and_then(|s| s.lines().last()) + .unwrap_or_default(); // If there is no indentation, use four-space. indentation_prefix = Some(if decor_prefix.is_empty() { " ".to_string() } else { - decor_prefix + decor_prefix.to_string() }); } diff --git a/crates/uv/tests/it/edit.rs b/crates/uv/tests/it/edit.rs index 94607c90477c..fb79fc9c0251 100644 --- a/crates/uv/tests/it/edit.rs +++ b/crates/uv/tests/it/edit.rs @@ -6389,10 +6389,10 @@ fn add_preserves_open_bracket_comment() -> Result<()> { version = "0.1.0" requires-python = ">=3.12" dependencies = [ # comment 0 - # comment 1 - "anyio==3.7.0", # comment 2 - # comment 3 - "requests==2.31.0", + # comment 1 + "anyio==3.7.0", # comment 2 + # comment 3 + "requests==2.31.0", ] [build-system]