Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit 158225e

Browse files
authored
featgRemove newlines, spaces, and tabs from status string (#310)
* Remove newlines, spaces, and tabs from status string * Added test of regex
1 parent fb28455 commit 158225e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/poller.js

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class Poller {
161161
}
162162

163163
async _updateStatus (status) {
164+
// Remove newlines, spaces, and tabs from status string
165+
status = status.replace(/(\r\n|\n|\r| (?= ))/gm, '').replace(/\t/g, ' ')
166+
164167
try {
165168
this._logger.debug(`updating status for ${this._namespace}/${this._name} to: ${status}`)
166169
await this._status.put({

lib/poller.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ describe('Poller', () => {
405405
expect(error).to.not.equal(undefined)
406406
expect(error.message).equals('Not Found')
407407
})
408+
409+
it('handles odd whitespace and newlines in status', async () => {
410+
const poller = pollerFactory()
411+
412+
await poller._updateStatus('\n\n\nLots of spaces\n\n\n').then(() => {
413+
const statusMessage = externalSecretsApiMock.status.put.getCall(0).args[0].body.status.status
414+
expect(statusMessage).to.equal('Lots of spaces')
415+
})
416+
})
408417
})
409418

410419
describe('_scheduleNextPoll', () => {

0 commit comments

Comments
 (0)