Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit d36addc

Browse files
authored
Merge pull request #1103 from flavio/fix-push-annotations
fix: handle single lines terminated by carriage return
2 parents ba69c50 + 73f381a commit d36addc

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/push.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use policy_evaluator::{
99
},
1010
policy_metadata::Metadata,
1111
};
12-
use tracing::warn;
12+
use tracing::{debug, warn};
1313

1414
use crate::backend::BackendDetector;
1515

@@ -61,16 +61,16 @@ fn build_oci_annotations(annotations: BTreeMap<String, String>) -> BTreeMap<Stri
6161
let mut annotations: BTreeMap<String, String> = annotations
6262
.iter()
6363
.filter(|(k, v)| {
64-
let filter = v.lines().count() <= 1;
65-
if filter {
64+
let keep = v.lines().count() <= 1;
65+
if !keep {
6666
warn!(
6767
annotation = k,
6868
"annotation is a multi-line string, it will be removed from the OCI manifest",
6969
);
7070
}
71-
filter
71+
keep
7272
})
73-
.map(|(k, v)| (k.to_owned(), v.to_owned()))
73+
.map(|(k, v)| (k.to_owned(), v.trim().to_owned()))
7474
.collect();
7575

7676
if let Some(source) = annotations.get(KUBEWARDEN_ANNOTATION_POLICY_SOURCE) {
@@ -82,14 +82,17 @@ fn build_oci_annotations(annotations: BTreeMap<String, String>) -> BTreeMap<Stri
8282
}
8383
}
8484

85+
debug!("OCI annotations: {:?}", annotations);
86+
8587
annotations
8688
}
8789

8890
#[cfg(test)]
8991
mod tests {
9092
use super::*;
9193
use policy_evaluator::constants::{
92-
KUBEWARDEN_ANNOTATION_POLICY_URL, KUBEWARDEN_ANNOTATION_POLICY_USAGE,
94+
KUBEWARDEN_ANNOTATION_POLICY_DESCRIPTION, KUBEWARDEN_ANNOTATION_POLICY_URL,
95+
KUBEWARDEN_ANNOTATION_POLICY_USAGE,
9396
};
9497

9598
#[test]
@@ -110,6 +113,10 @@ mod tests {
110113
KUBEWARDEN_ANNOTATION_POLICY_USAGE.to_string(),
111114
"this is a multi-line\nstring".to_string(),
112115
);
116+
annotations.insert(
117+
KUBEWARDEN_ANNOTATION_POLICY_DESCRIPTION.to_string(),
118+
"this is a line that ends with a line terminator\n".to_string(),
119+
);
113120

114121
let actual = build_oci_annotations(annotations);
115122

@@ -126,6 +133,12 @@ mod tests {
126133
actual.get(KUBEWARDEN_ANNOTATION_POLICY_SOURCE).unwrap(),
127134
policy_source
128135
);
136+
assert_eq!(
137+
actual
138+
.get(KUBEWARDEN_ANNOTATION_POLICY_DESCRIPTION)
139+
.unwrap(),
140+
"this is a line that ends with a line terminator",
141+
);
129142
}
130143

131144
#[test]

0 commit comments

Comments
 (0)