From 57081a6cc9d658effdf46e15be925dcf47ccea9b Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Sat, 4 Jan 2025 05:00:01 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=98=EB=AA=BB=20=EB=A7=A4=ED=95=91?= =?UTF-8?q?=EB=90=9C=20image=20path=20=EC=A0=95=EB=A6=AC=20/=20tag=20regex?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 39355e6..df246bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ fn main() { if let Ok(value) = env::var("KANIKO_IMAGE_TAGS") { env::remove_var("KANIKO_IMAGE_TAGS"); - let pattern = Regex::new(r"^[a-zA-Z0-9_\\-.]+$").unwrap(); + let pattern = Regex::new(r"^[-a-zA-Z0-9_\.]+$").unwrap(); for tag in value.split(',') { let tag = tag.trim(); if !pattern.is_match(tag) { @@ -39,15 +39,13 @@ fn main() { } } - let image = match (repository.chars().last(), name.chars().last()) { - (Some('/'), Some('/')) => format!("{}{}", repository.trim_end_matches("/"), name), - (Some('/'), Some(_)) => format!("{}{}", repository, name), - (Some(_), Some('/')) => format!("{}{}", repository, name), - (Some(_), Some(_)) => format!("{}/{}", repository, name), - (None, Some(_)) => name, - (Some(_), None) => repository, - (None, None) => "".to_string(), - }; + let image = format!( + "{}/{}", + repository.trim_end_matches("/"), + name.trim_start_matches("/") + ) + .trim_matches(&['/'] as &[_]) + .to_string(); let mut args: Vec<_> = env::args().skip(1).collect(); if !image.is_empty() {