Fix tool name whitespace parsing bug
Problem
The tool name parsing logic in main.sh had incorrect parameter expansions for trimming whitespace:
t="${REPLY# *}" # Incorrect: removes leading space + any chars
tools+=("${t%* }") # Incorrect: removes shortest match of "any chars + space" from end
This caused version strings to contain stray characters when tool names had unexpected whitespace, leading to semver validation failures with errors like:
Error: install-action does not support semver operators: '0.10.3
'
The debug output showed the version was parsed as '0.10.3 with both a leading single quote and the closing quote appearing on a separate line, instead of the expected clean 0.10.3.
Solution
Replaced the faulty whitespace trimming with proper bash parameter expansion patterns:
# Trim leading and trailing whitespace
t="${REPLY}"
t="${t#"${t%%[![:space:]]*}"}" # Remove leading whitespace
t="${t%"${t##*[![:space:]]}"}" # Remove trailing whitespace
tools+=("${t}")
This uses the standard bash idiom for trimming whitespace:
"${t%%[![:space:]]*}"finds the leading whitespace"${t#...}"removes it from the beginning"${t##*[![:space:]]}"finds the trailing whitespace"${t%...}"removes it from the end
Example Usage
This bug affects any tool specification, even with hard-coded versions:
- name: Install Cargo Tools
uses: taiki-e/install-action@v2
with:
tool: |
cargo-lambda
[email protected]
The faulty parsing logic in the action's internal tool processing would corrupt even hard-coded version strings with stray quotes, causing semver validation to fail with errors like '0.10.3 instead of the expected 0.10.3.
Thanks for the PR.
Error: install-action does not support semver operators: '0.10.3 'The debug output showed the version was parsed as
'0.10.3with both a leading single quote and the closing quote appearing on a separate line, instead of the expected clean0.10.3.
Single quote is not a part of the version; they are used to ensure proper output even for broken version strings containing line breaks. In this case, version is actually parsed as 0.10.3\n.
tool: | cargo-lambda [email protected]
As documented in readme, we currently only supports comma-separated list, not space-separated.
Name Required Description Type Default tool ✓ Tools to install (comma-separated list) String
I'm open to accepting space-separated list support, but it doesn't seem to be implemented correctly in this PR.
I think the approach to properly handle spaces here is to perform the following processing before the while loop:
<ws>*@<ws>*->@- if contains comma,
- then
<ws>*,<ws>*->, - else
<ws>+->,
- then
^<ws>+-> (remove)<ws>+$-> (remove)
(<ws> is space ( ), tab (\t), and line breaks (\n and \r))
Opened https://github.com/taiki-e/install-action/pull/1366 to support whitespace separated list per https://github.com/taiki-e/install-action/pull/1147#issuecomment-3291116129.