Skip to content

Commit

Permalink
fix: escape docker error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
loispostula committed Nov 26, 2024
1 parent b33dd69 commit 607a453
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
18 changes: 16 additions & 2 deletions src/commands/check_workspace/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,13 +222,27 @@ impl Docker {
}
}
}

// Custom serialization function for `error`
fn serialize_error_escaped<S>(value: &Option<String>, serializer: S) -> Result<S::Ok, S::Error>
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<String>,
pub context: Option<String>,
pub dockerfile: Option<String>,
#[serde(default, serialize_with = "serialize_error_escaped")]
pub error: Option<String>,
}

Expand Down

0 comments on commit 607a453

Please sign in to comment.