Skip to content

Commit

Permalink
Exclude heredoc from normalization (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout authored Dec 2, 2024
1 parent 0bc3ee6 commit 14ddd60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/extension/executors/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,12 @@ export function prepareCommandSeq(cellText: string, languageId: string): string[
return cellText ? cellText.split('\n') : []
}

return cellText.split('\n').map((l) => {
const isHeredoc = cellText.indexOf('<<') !== -1

return cellText.split('\n').map((l: string) => {
const stripped = l.trimStart()

if (stripped.startsWith('$')) {
if (stripped.startsWith('$') && !isHeredoc) {
return stripped.slice(1).trimStart()
}

Expand Down
8 changes: 8 additions & 0 deletions tests/extension/executors/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ suite('prepareCmdSeq', () => {
'echo 4',
])
})

test('should not remove leading dollar signs from heredoc', () => {
const heredoc = `Foo="bar"
cat << EOF
$Foo
EOF`
expect(prepareCommandSeq(heredoc, 'sh')).toStrictEqual(heredoc.split('\n'))
})
})

suite('promptVariablesAsync function', () => {
Expand Down

0 comments on commit 14ddd60

Please sign in to comment.