mirror of https://github.com/actions/toolkit
Merge pull request #1185 from bicstone/bicstone/fix-getMultilineInput-trim
fix(core): `getMultilineInput` not trimming whitespacepull/1187/head
commit
4df45177e4
|
@ -33,8 +33,8 @@ const testEnvVars = {
|
||||||
INPUT_BOOLEAN_INPUT_FALSE3: 'FALSE',
|
INPUT_BOOLEAN_INPUT_FALSE3: 'FALSE',
|
||||||
INPUT_WRONG_BOOLEAN_INPUT: 'wrong',
|
INPUT_WRONG_BOOLEAN_INPUT: 'wrong',
|
||||||
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',
|
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',
|
||||||
|
|
||||||
INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',
|
INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',
|
||||||
|
INPUT_LIST_WITH_TRAILING_WHITESPACE: ' val1 \n val2 \n ',
|
||||||
|
|
||||||
// Save inputs
|
// Save inputs
|
||||||
STATE_TEST_1: 'state_val',
|
STATE_TEST_1: 'state_val',
|
||||||
|
@ -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', () => {
|
it('getInput trims whitespace by default', () => {
|
||||||
expect(core.getInput('with trailing whitespace')).toBe('some val')
|
expect(core.getInput('with trailing whitespace')).toBe('some val')
|
||||||
})
|
})
|
||||||
|
@ -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', () => {
|
it('setOutput produces the correct command', () => {
|
||||||
core.setOutput('some output', 'some value')
|
core.setOutput('some output', 'some value')
|
||||||
assertWriteCalls([
|
assertWriteCalls([
|
||||||
|
|
|
@ -170,7 +170,11 @@ export function getMultilineInput(
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(x => x !== '')
|
.filter(x => x !== '')
|
||||||
|
|
||||||
return inputs
|
if (options && options.trimWhitespace === false) {
|
||||||
|
return inputs
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputs.map(input => input.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue