MCPcopy
hub / github.com/ganeshrvel/openmtp / escapeShellMtp

Function escapeShellMtp

app/api/sys/index.js:47–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45 * This hack is to support flex quotes parser for mtp cli.
46 */
47export const escapeShellMtp = cmd => {
48 if (cmd.indexOf(`\\"`) !== -1 && cmd.indexOf(`"\\`) !== -1) {
49 return cmd
50 .replace(/`/g, '\\`')
51 .replace(/\\/g, `\\\\\\\\`)
52 .replace(/"/g, `\\\\\\"`);
53 }
54 if (cmd.indexOf(`"\\"`) !== -1) {
55 return cmd
56 .replace(/`/g, '\\`')
57 .replace(/\\/g, `\\\\\\\\`)
58 .replace(/"/g, `\\\\\\"`);
59 }
60 if (cmd.indexOf(`\\"`) !== -1) {
61 return cmd
62 .replace(/`/g, '\\`')
63 .replace(/\\/g, `\\\\\\`)
64 .replace(/"/g, `\\\\\\\\"`);
65 }
66 if (cmd.indexOf(`"\\`) !== -1) {
67 return cmd
68 .replace(/`/g, '\\`')
69 .replace(/\\/g, `\\\\\\\\`)
70 .replace(/"/g, `\\\\\\"`);
71 }
72 return cmd
73 .replace(/`/g, '\\`')
74 .replace(/\\/g, `\\\\\\`)
75 .replace(/"/g, `\\\\\\"`);
76};
77
78const mtpCli = `"${escapeShellMtp(_mtpCli)}"`;
79

Callers 7

index.jsFile · 0.85
checkMtpFileExistsFunction · 0.85
asyncReadMtpDirFunction · 0.85
renameMtpFilesFunction · 0.85
delMtpFilesFunction · 0.85
newMtpFolderFunction · 0.85
pasteFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected