Skip to content

Commit 823619f

Browse files
mikolalysenkoclaude
andcommitted
Read an empty <type> as jar when a profile moves coordinates
A `${…}` groupId / artifactId declaration with an empty `<type></type>` gave no reading once a profile's <properties> moved it: classpath_copy treated the empty type as "no jar on the classpath", while Maven (and is_main_jar / is_variant everywhere else) reads it as the default jar. So a declaration a profile turned into the pinned GA at another version went unweighed: hosted scan wrote the pin and VEX attested it (a false attestation, carried over from the folded #2026). An empty type now maps like `jar`. Tests: a withheld case in profile_properties_turning_a_declaration_into_the_pinned_ga_are_not_attested and a refused case in maven_pom_profile_moved_coordinates_refuse_the_dep, both failing before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent eda7b20 commit 823619f

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,14 +958,15 @@ pub(crate) fn is_variant(type_text: Option<&str>, classifier: Option<&str>) -> b
958958
/// Which copy of its GA a declaration's `<type>` / `<classifier>` read as
959959
/// when a profile moves its coordinates: `Some(None)` the main jar,
960960
/// `Some(Some(c))` the classifier copy `c`, `None` no jar on the classpath.
961-
/// `test-jar` is the `tests` copy, an explicit classifier names the copy
962-
/// whatever the type, and a `${…}` type may be `jar`.
961+
/// An empty `<type>` is Maven's default `jar`, `test-jar` is the `tests`
962+
/// copy, an explicit classifier names the copy whatever the type, and a
963+
/// `${…}` type may be `jar`.
963964
pub(crate) fn classpath_copy<'a>(
964965
type_text: Option<&'a str>,
965966
classifier: Option<&'a str>,
966967
) -> Option<Option<&'a str>> {
967968
match (type_text, classifier) {
968-
(None | Some("jar"), c) => Some(c),
969+
(None | Some("" | "jar"), c) => Some(c),
969970
(Some(t), c) if t.contains("${") => Some(c),
970971
(Some("test-jar"), None) => Some(Some("tests")),
971972
(Some(_), Some(c)) => Some(Some(c)),

‎crates/socket-patch-core/src/patch/redirect/mod.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11013,6 +11013,12 @@ mod tests {
1101311013
format!("{pinned}{}", decl("${h}", "slf4j-api", "1.7.30")),
1101411014
"<h>org.slf4j</h>",
1101511015
),
11016+
// ... with an empty `<type>`, Maven's default `jar`.
11017+
(
11018+
"<h>org.other</h>",
11019+
pinned.clone() + &h_decl(Some("1.7.30"), "<type></type>"),
11020+
"<h>org.slf4j</h>",
11021+
),
1101611022
// ... or its executable classifier copy.
1101711023
(
1101811024
"<h>org.other</h>",

‎crates/socket-patch-core/src/vex/discover/maven.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,13 @@ mod tests {
25722572
vec![to_slf4j.clone()],
25732573
None,
25742574
),
2575+
// An empty `<type>` is Maven's default, `jar`.
2576+
case(
2577+
h,
2578+
with(&other_with("1.7.30", "<type></type>")),
2579+
vec![to_slf4j.clone()],
2580+
None,
2581+
),
25752582
// Managed, where management governs the pin.
25762583
case(
25772584
h,

0 commit comments

Comments
 (0)