| 45 | * This hack is to support flex quotes parser for mtp cli. |
| 46 | */ |
| 47 | export 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 | |
| 78 | const mtpCli = `"${escapeShellMtp(_mtpCli)}"`; |
| 79 |
no outgoing calls
no test coverage detected