From 607a453f331a8f26f3c9dd1346277fa57f73c38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFs=20Postula?= Date: Tue, 26 Nov 2024 08:20:33 +0100 Subject: [PATCH] fix: escape docker error logs --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/check_workspace/docker.rs | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fa7fb3..7c63aa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -294,7 +294,7 @@ dependencies = [ [[package]] name = "cargo-fslabscli" -version = "2.4.2" +version = "2.4.3" dependencies = [ "anyhow", "assert_fs", diff --git a/Cargo.toml b/Cargo.toml index d31a2e9..2231830 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-fslabscli" -version = "2.4.2" +version = "2.4.3" edition = "2021" authors = ["FSLABS DevOps Gods"] repository = "https://github.com/ForesightMiningSoftwareCorporation/fslabsci" diff --git a/src/commands/check_workspace/docker.rs b/src/commands/check_workspace/docker.rs index bc5cc55..10e247d 100644 --- a/src/commands/check_workspace/docker.rs +++ b/src/commands/check_workspace/docker.rs @@ -2,7 +2,7 @@ use oci_distribution::client::{ClientConfig, ClientProtocol}; use oci_distribution::errors::{OciDistributionError, OciErrorCode}; use oci_distribution::secrets::RegistryAuth; use oci_distribution::{Client as DockerClient, Reference}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize, Serializer}; use std::collections::HashMap; use std::env; use std::fs::File; @@ -222,13 +222,27 @@ impl Docker { } } } - +// Custom serialization function for `error` +fn serialize_error_escaped(value: &Option, serializer: S) -> Result +where + S: Serializer, +{ + if let Some(ref v) = value { + let escaped = v + .replace('\\', "\\\\") // Escape backslashes + .replace('"', "\\\""); // Escape quotes + serializer.serialize_some(&escaped) + } else { + serializer.serialize_none() + } +} #[derive(Serialize, Deserialize, Clone, Default, Debug)] pub struct PackageMetadataFslabsCiPublishDocker { pub publish: bool, pub repository: Option, pub context: Option, pub dockerfile: Option, + #[serde(default, serialize_with = "serialize_error_escaped")] pub error: Option, }