* Joins shell continuation lines (backslash-newline) into a single line. * Only joins when there's an odd number of backslashes before the newline * (the last one escapes the newline). Even backslashes pair up as escape * sequences and the newline remains a separator.
(command: string)
| 281 | * sequences and the newline remains a separator. |
| 282 | */ |
| 283 | function joinContinuationLines(command: string): string { |
| 284 | return command.replace(/\\+\n/g, match => { |
| 285 | const backslashCount = match.length - 1 // -1 for the newline |
| 286 | if (backslashCount % 2 === 1) { |
| 287 | // Odd number: last backslash escapes the newline (line continuation) |
| 288 | return '\\'.repeat(backslashCount - 1) |
| 289 | } else { |
| 290 | // Even number: all pair up, newline is a real separator |
| 291 | return match |
| 292 | } |
| 293 | }) |
| 294 | } |
| 295 |
no outgoing calls
no test coverage detected