MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_powershell_quote_word

Function cbm_powershell_quote_word

src/cli/cli.c:4670–4698  ·  view source on GitHub ↗

PowerShell single-quoted words are literal; an apostrophe is represented by * two apostrophes. This prevents $env expansion and command substitution. */

Source from the content-addressed store, hash-verified

4668/* PowerShell single-quoted words are literal; an apostrophe is represented by
4669 * two apostrophes. This prevents $env expansion and command substitution. */
4670static int cbm_powershell_quote_word(const char *value, char *out, size_t out_size) {
4671 if (!value || !out || out_size < CLI_PAIR_LEN) {
4672 return CLI_ERR;
4673 }
4674 size_t used = 0U;
4675 out[used++] = '\'';
4676 for (const unsigned char *cursor = (const unsigned char *)value; *cursor; cursor++) {
4677 if (*cursor < 0x20U || *cursor == 0x7fU) {
4678 out[0] = '\0';
4679 return CLI_ERR;
4680 }
4681 size_t needed = *cursor == '\'' ? 2U : 1U;
4682 if (needed > out_size - used - CLI_PAIR_LEN) {
4683 out[0] = '\0';
4684 return CLI_ERR;
4685 }
4686 out[used++] = (char)*cursor;
4687 if (*cursor == '\'') {
4688 out[used++] = '\'';
4689 }
4690 }
4691 if (used >= out_size - CLI_SKIP_ONE) {
4692 out[0] = '\0';
4693 return CLI_ERR;
4694 }
4695 out[used++] = '\'';
4696 out[used] = '\0';
4697 return CLI_OK;
4698}
4699
4700static bool cbm_write_owned_hook_script_with_legacy(const char *path, const char *script,
4701 const char *const *legacy_scripts,

Calls

no outgoing calls

Tested by

no test coverage detected