Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): getMultilineInput not trimming whitespace #1185

Merged
merged 1 commit into from Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 32 additions & 9 deletions packages/core/__tests__/core.test.ts
Expand Up @@ -33,8 +33,8 @@ const testEnvVars = {
INPUT_BOOLEAN_INPUT_FALSE3: 'FALSE',
INPUT_WRONG_BOOLEAN_INPUT: 'wrong',
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',

INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',
INPUT_LIST_WITH_TRAILING_WHITESPACE: ' val1 \n val2 \n ',

// Save inputs
STATE_TEST_1: 'state_val',
Expand Down Expand Up @@ -212,14 +212,6 @@ describe('@actions/core', () => {
)
})

it('getMultilineInput works', () => {
expect(core.getMultilineInput('my input list')).toEqual([
'val1',
'val2',
'val3'
])
})

it('getInput trims whitespace by default', () => {
expect(core.getInput('with trailing whitespace')).toBe('some val')
})
Expand Down Expand Up @@ -260,6 +252,37 @@ describe('@actions/core', () => {
)
})

it('getMultilineInput works', () => {
expect(core.getMultilineInput('my input list')).toEqual([
'val1',
'val2',
'val3'
])
})

it('getMultilineInput trims whitespace by default', () => {
expect(core.getMultilineInput('list with trailing whitespace')).toEqual([
'val1',
'val2'
])
})

it('getMultilineInput trims whitespace when option is explicitly true', () => {
expect(
core.getMultilineInput('list with trailing whitespace', {
trimWhitespace: true
})
).toEqual(['val1', 'val2'])
})

it('getMultilineInput does not trim whitespace when option is false', () => {
expect(
core.getMultilineInput('list with trailing whitespace', {
trimWhitespace: false
})
).toEqual([' val1 ', ' val2 ', ' '])
})

it('setOutput produces the correct command', () => {
core.setOutput('some output', 'some value')
assertWriteCalls([
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/core.ts
Expand Up @@ -170,7 +170,11 @@ export function getMultilineInput(
.split('\n')
.filter(x => x !== '')

return inputs
if (options && options.trimWhitespace === false) {
return inputs
}

return inputs.map(input => input.trim())
}

/**
Expand Down