Skip to content

fix(tests): '\$[' is read as the deprecated $[...] arithmetic form - #60

Open
hyperpolymath wants to merge 1 commit into
mainfrom
fix/shellcheck-parse-error
Open

fix(tests): '\$[' is read as the deprecated $[...] arithmetic form#60
hyperpolymath wants to merge 1 commit into
mainfrom
fix/shellcheck-parse-error

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

security-tests.sh:72 embedded '\$[{]?' in a double-quoted string. After bash processes the escape this leaves '$[', which is the obsolete arithmetic-expansion syntax, so the file failed to parse. Escaped so a literal dollar reaches the regex, preserving the intended ERE.

Found by an estate-wide shellcheck sweep of 5,111 tracked scripts across 375 repos: 11 files fail to parse (SC1073/SC1072). shellcheck stops analysing at the failure, so everything after it was never checked either.

Verified: shellcheck -S error reports 0 parse errors for the file(s) touched.

security-tests.sh:72 embedded '\\$[{]?' in a double-quoted string. After bash processes the escape this leaves '$[', which is the obsolete arithmetic-expansion syntax, so the file failed to parse. Escaped so a literal dollar reaches the regex, preserving the intended ERE.

Found by an estate-wide shellcheck sweep of 5,111 tracked scripts across 375
repos: 11 files fail to PARSE (SC1073/SC1072). shellcheck stops analysing at
the failure, so everything after it in the file was never checked either.

Verified: shellcheck -S error reports 0 parse errors for the file(s) touched.
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 82f16dfb-3ee0-4a23-957a-9f59bdacc3e1

📥 Commits

Reviewing files that changed from the base of the PR and between 6398e1a and 26fcdba.

📒 Files selected for processing (1)
  • tests/security-tests.sh

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
tests/security-tests.sh (1)

72-72: LGTM!


📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Improved security test detection for unsafe eval usage, reducing the risk of missed or incorrect matches while continuing to ignore commented code.

Walkthrough

The security test updates the unsafe-eval detection regex to escape the dollar sign. The test command and exclusion of commented matches remain unchanged.

Changes

Security test validation

Layer / File(s) Summary
Unsafe eval regex correction
tests/security-tests.sh
The unsafe-eval check now uses an escaped dollar sign. Its command and comment filtering remain unchanged.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 26fcd

This localized test-script fix restores parsing while preserving the intended regular expression, and no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: metadatastician

Poem

A rabbit checks the shell at night
The dollar sign is safely tight
Comments stay outside the scan
The test runs as it began
Clean regex, clear and bright

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the shell parsing issue caused by the deprecated $[...] arithmetic form and relates directly to the test fix.
Description check ✅ Passed The description accurately explains the parsing error, the escaping fix, and the ShellCheck verification for the changed file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
E Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@gitar-bot

gitar-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR successfully addresses the ShellCheck parsing error (SC1072/SC1073) caused by the deprecated arithmetic expansion syntax. While Codacy indicates the PR is up to standards, the internal logic of the 'eval' safety check in tests/security-tests.sh remains problematic.

The security check can be trivially bypassed by adding a trailing comment to an unsafe line, and the regex currently fails to detect common injection vectors such as positional parameters ($1) or special variables ($@). Furthermore, there is no automated test or CI step included to prevent future ShellCheck regressions.

About this PR

  • Although the parsing issue is fixed, the PR does not include an automated check or CI configuration to ensure the script remains ShellCheck-compliant in the future.

Test suggestions

  • Verify the script passes ShellCheck analysis without syntax/parse errors.
  • Verify the regex correctly identifies unsafe eval usage (e.g., 'eval $VAR' or 'eval ${VAR').
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify the script passes ShellCheck analysis without syntax/parse errors.
2. Verify the regex correctly identifies unsafe eval usage (e.g., 'eval $VAR' or 'eval ${VAR').

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread tests/security-tests.sh

# Should not have eval of user input without validation
test_assert "${script_name} doesn't have unsafe eval" "! grep -E 'eval .*\\$[{]?[a-zA-Z_]+' \"${script}\" | grep -qv '#'"
test_assert "${script_name} doesn't have unsafe eval" "! grep -E 'eval .*\\\$[{]?[a-zA-Z_]+' \"${script}\" | grep -qv '#'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

The 'eval' safety check has two significant issues: 1) It is easily bypassed by trailing comments (e.g., 'eval $VAR # comment') because the current implementation discards any line containing a hash. 2) The regex '[a-zA-Z_]+' fails to detect positional parameters ($1, $2) or special variables ($@, $*), which are common sources of injection. Consider replacing this check with a more robust regex that ignores leading comments but captures a broader set of variable patterns: ! grep -E '^[[:space:]]*[^#]*eval .*\\\$[({]?[a-zA-Z0-9_*@?]'.

@hyperpolymath
hyperpolymath enabled auto-merge (squash) August 28, 2026 07:48
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