(jobName: string)
| 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("'", "'\"'\"'")}'`; |
no outgoing calls
no test coverage detected