Custom action: whitespace in input parameters is getting trimmed

I’ve developed an action that runs regex substitution on input strings, and today I’ve received a bug report that it is not possible to replace strings with whitespace: not able to replace char with whitespace · Issue #6 · frabert/replace-string-action · GitHub

From my brief testing it looks like core.getInput() behaves as if it automatically performs a trim() on the data. Is there any way to turn this behavior off?

I wasn’t sure if this could be a problem with YAML itself, but I’m fairly sure after some testing that the @actions/core package or something else provided by GitHub strips whitespace from action inputs. replace-with: "\u0020" (with double quotes) doesn’t work, even though that would be the way to escape something in YAML. The only solution that I can think of would be to add another input to let the action know that the input is JSON-encoded, pass the space in like replace-with: '" "' and let the action decode this input with JSON.parse().

1 Like

There’s actually a better way - @actions/core supports an option to turn trimming of whitespace off since v1.3.0: Core: Add trimWhiteSpace to getInput by luketomlinson · Pull Request #802 · actions/toolkit · GitHub

core.getInput('<name>', { trimWhitespace: false })
1 Like