{"version":3,"file":"snapCommand.js","sourceRoot":"","sources":["../../../src/targets/snap/snapCommand.ts"],"names":[],"mappings":";;AAOA,0DAMC;AASD,gCAEC;AAQD,wEASC;AAzCD,+CAAwD;AAExD;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,KAAa,EAAE,SAAiB;IACtE,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,wCAAyB,CACjC,GAAG,SAAS,4DAA4D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,GAAG,qEAAqE,CAC1K,CAAA;IACH,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,+FAA+F;AAC/F,kGAAkG;AAClG,0FAA0F;AAC1F,+GAA+G;AAE/G,0EAA0E;AAC1E,SAAgB,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,GAAG,CAAA;AAC/C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,8BAA8B,CAAC,IAA0C;IACvF,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;IAC/B,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;IACnD,IAAI,OAAO,GAAG,8BAA8B,QAAQ,GAAG,CAAA;IACvD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACjD,CAAC;IACD,OAAO,IAAI,SAAS,CAAA;IACpB,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { InvalidConfigurationError } from \"builder-util\"\n\n/**\n * Validates that a value is safe to embed in a double-quoted shell string.\n * Rejects characters that would be interpreted as shell metacharacters inside `\"...\"`:\n * `$`, backtick, `\"`, `\\`, and newlines.\n */\nexport function validateShellEmbeddable(value: string, fieldName: string): void {\n  if (/[$`\"\\\\\\r\\n]/.test(value)) {\n    throw new InvalidConfigurationError(\n      `${fieldName} contains characters that are not safe in shell scripts: ${JSON.stringify(value)}. ` + `Avoid $, backtick, double-quote, backslash, and newline characters.`\n    )\n  }\n}\n\n// snapd restricts the value of `apps.<app-name>.command` to alphanumeric characters, spaces, and\n// `/ . _ # : $ -`, and splits it on whitespace. Rather than encode those rules per-arg, core24\n// always routes the command through a launcher script (see buildSnapCommandLauncherScript), which\n// sidesteps the character restrictions entirely and keeps a single, uniform command path.\n// See: https://documentation.ubuntu.com/snapcraft/stable/reference/snapcraft-yaml/#apps.%3Capp-name%3E.command\n\n/** Single-quote a shell argument, escaping any embedded single quotes. */\nexport function shellQuote(arg: string): string {\n  return \"'\" + arg.replace(/'/g, \"'\\\\''\") + \"'\"\n}\n\n/**\n * Builds the contents of the launcher script that execs `$SNAP/app/<execName>` with the given args.\n * `$@` is forwarded so launch-time arguments still reach the app. The executable name is validated\n * against shell metacharacters and each arg is single-quoted, so embedded characters (e.g. `=`, quotes)\n * are passed literally.\n */\nexport function buildSnapCommandLauncherScript(opts: { execName: string; args: string[] }): string {\n  const { execName, args } = opts\n  validateShellEmbeddable(execName, \"executableName\")\n  let content = `#!/bin/sh\\nexec \"$SNAP/app/${execName}\"`\n  if (args.length > 0) {\n    content += \" \" + args.map(shellQuote).join(\" \")\n  }\n  content += ' \"$@\"\\n'\n  return content\n}\n"]}