Skip to content

Fix unbalanced parens in series-version regex (get_latest_installed_version)#184

Open
fsnow wants to merge 1 commit into
aheckmann:masterfrom
fsnow:fix/series-regex-unbalanced-parens
Open

Fix unbalanced parens in series-version regex (get_latest_installed_version)#184
fsnow wants to merge 1 commit into
aheckmann:masterfrom
fsnow:fix/series-regex-unbalanced-parens

Conversation

@fsnow

@fsnow fsnow commented Jun 13, 2026

Copy link
Copy Markdown

Problem

get_latest_installed_version() uses a regex to detect a 2-part series version (e.g. 8.3) so it can resolve it to the latest installed patch. The regex has a typo — the first character class is written [0-9)] instead of [0-9]+):

if [[ $version =~ ^([0-9)]\.([0-9]+)(-ent)?$ ]]; then

This does two things:

  1. Drops the + quantifier on the major-version digits.
  2. Swallows capture group 1's closing paren into the character class.

The result is 3 opening parens but only 2 closing parens, so Bash rejects the whole regex at runtime:

m: line 1506: [[: invalid regular expression `^([0-9)]\.([0-9]+)(-ent)?$': parentheses not balanced

Impact

  • m <major>.<minor> series resolution against installed versions is broken.
  • The error is printed to stderr on every code path that reaches get_latest_installed_version, including a plain m 8.3.4 install, since the [[ =~ ]] test errors rather than returning false.

Repro

version=8.3
[[ $version =~ ^([0-9)]\.([0-9]+)(-ent)?$ ]]; echo $?
# bash: ... parentheses not balanced
# 2

Fix

Correct the character class to [0-9]+) so group 1 captures the major version, matching how the following lines use BASH_REMATCH[1]/[2]:

-  if [[ $version =~ ^([0-9)]\.([0-9]+)(-ent)?$ ]]; then
+  if [[ $version =~ ^([0-9]+)\.([0-9]+)(-ent)?$ ]]; then

After the fix:

version=8.3
[[ $version =~ ^([0-9]+)\.([0-9]+)(-ent)?$ ]]; echo "$? ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}"
# 0 8 3

One-line change; no behavior change other than making the intended match work and silencing the error.

The regex detecting a 2-part series (e.g. 8.3) had a typo: the character
class was written `[0-9)]` instead of `[0-9]+)`. That both drops the `+`
quantifier and swallows capture group 1's closing paren, leaving 3 open
parens and 2 close parens, so Bash rejects the regex outright:

    m: line 1506: [[: invalid regular expression
    `^([0-9)]\.([0-9]+)(-ent)?$': parentheses not balanced

The error prints on every path that reaches get_latest_installed_version,
including a plain `m 8.3.4` install, and breaks `m <major>.<minor>` series
resolution. Correct the class to `[0-9]+)` so group 1 captures the major
version as the following lines (BASH_REMATCH[1]/[2]) expect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant