MCPcopy
hub / github.com/firecow/gitlab-ci-local / safeDockerString

Method safeDockerString

src/utils.ts:56–69  ·  view source on GitHub ↗
(jobName: string)

Source from the content-addressed store, hash-verified

54 static readonly MAX_FILENAME_LENGTH = 255 - 17; // NAME_MAX (bytes) - wrapper
55
56 static safeDockerString (jobName: string) {
57 // INVARIANT: \w without /u is ASCII-only ([A-Za-z0-9_]), so `encoded` is pure ASCII
58 // and .length === byte length. NAME_MAX is a byte limit — adding /u would break this.
59 // We hash `jobName` (not `encoded`) because base64url encoding isn't injective.
60 const encoded = jobName.replace(/[^\w-]+/g, (match) => {
61 return base64url.encode(match);
62 });
63 if (encoded.length <= Utils.MAX_FILENAME_LENGTH) {
64 return encoded;
65 }
66 const hash = createHash("sha256").update(jobName).digest("hex").substring(0, 16);
67 const prefix = encoded.substring(0, Utils.MAX_FILENAME_LENGTH - 1 - hash.length);
68 return `${prefix}-${hash}`;
69 }
70
71 static safeBashString (s: string) {
72 return `'${s.replaceAll("'", "'\"'\"'")}'`;

Callers 6

safeJobNameMethod · 0.80
mountCacheCmdMethod · 0.80
copyArtifactsInMethod · 0.80
printReportMethod · 0.80
utils.test.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected