Skip to content

Commit 79eeb91

Browse files
Merge #1078
1078: Fix custom image names for images with a trailing '-' character. r=Emilgardis a=Alexhuszagh Closes #1077. Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
2 parents c686539 + 10da1e0 commit 79eeb91

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changes/1078.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "fixed",
3+
"description": "Fix custom image names for images with a trailing '-' character.\ncustom images in packages with the `^[^0-9-].*([^A-Za-z_]*-)|(-[^A-Za-z_]*)$` package name pattern are now supported.",
4+
"issues": [1077]
5+
}

src/docker/custom.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fn docker_tag_name(file_name: &str) -> String {
259259
let mut consecutive_underscores = 0;
260260
for c in file_name.chars() {
261261
match c {
262-
'a'..='z' | '.' | '-' => {
262+
'a'..='z' | '0'..='9' | '.' | '-' => {
263263
consecutive_underscores = 0;
264264
result.push(c);
265265
}
@@ -278,7 +278,11 @@ fn docker_tag_name(file_name: &str) -> String {
278278
}
279279
}
280280

281-
// in case all characters were invalid, use a non-empty filename
281+
// in case all characters were invalid or we had all non-ASCII
282+
// characters followed by a `-`, we use a non-empty filename
283+
if result.ends_with('-') {
284+
result.pop();
285+
}
282286
if result.is_empty() {
283287
result = "empty".to_owned();
284288
}
@@ -312,5 +316,8 @@ mod tests {
312316
docker_tag_name("pAcKaGe---test.name"),
313317
s!("package---test.name")
314318
);
319+
320+
assert_eq!(docker_tag_name("foo-123"), s!("foo-123"));
321+
assert_eq!(docker_tag_name("foo-123-"), s!("foo-123"));
315322
}
316323
}

0 commit comments

Comments
 (0)