Skip to content

fix: reject malformed --go-version values - #24

Open
AtiqDev (atiqur-rahman-pro) wants to merge 1 commit into
JetBrains:mainfrom
atiqur-rahman-pro:fix/strict-go-version-validation
Open

fix: reject malformed --go-version values#24
AtiqDev (atiqur-rahman-pro) wants to merge 1 commit into
JetBrains:mainfrom
atiqur-rahman-pro:fix/strict-go-version-validation

Conversation

@atiqur-rahman-pro

Copy link
Copy Markdown
  • Replace loose regex matching with strictGoVersionPattern anchored to input boundaries
  • Reject invalid version strings like '1.24x', 'invalid.ver', and 'abc1.24'
  • Add TestNormalizeGoVersionStrictRejection regression tests

Summary

This PR makes validation of the explicit --go-version argument stricter.

Currently, a malformed value containing trailing characters is accepted because the parser extracts a valid-looking version
substring instead of validating the complete input.

Reproduction

Environment:

  • Windows amd64
  • Go 1.26.7
  • Upstream commit reviewed: 40781f167719913666fe2a7dc1c77ea6f256df0a
go run . list --go-version=1.24invalid
echo %ERRORLEVEL%

Current behavior
The value is interpreted as Go 1.24.
Go 1.24 guidelines are printed.
The command exits with code 0.

Documented valid formats should continue to work:

1.24
go1.24.3
devel
Changes
Validate the complete explicit Go-version value instead of accepting a matching substring.
Add regression coverage for trailing invalid characters.
Preserve support for valid version formats and Go toolchain output.
Verification
cmd

go test -count=1 ./...
go vet ./...
gofmt -l .
Manual negative case:

cmd

go run . list --go-version=1.24invalid
echo %ERRORLEVEL%
Expected: parsing error and nonzero exit code.

• The content is good, but the first code block is not closed, so the remaining description will render incorrectly. Use this
corrected version:

## Summary

This PR makes validation of the explicit `--go-version` argument stricter.

Currently, a malformed value containing trailing characters is accepted because the parser extracts a valid-looking version
substring instead of validating the complete input.

## Reproduction

Environment:

- Windows amd64
- Go 1.26.7
- Upstream commit reviewed: `40781f167719913666fe2a7dc1c77ea6f256df0a`

```cmd
go run . list --go-version=1.24invalid
echo %ERRORLEVEL%

## Current behavior

- The value is interpreted as Go 1.24.
- Go 1.24 guidelines are printed.
- The command exits with code 0.

## Expected behavior

The CLI should reject 1.24invalid as malformed and return a nonzero exit code.

Documented valid formats should continue to work:

- 1.24
- go1.24.3
- devel

## Changes

- Validate the complete explicit Go-version value instead of accepting a matching substring.
- Add regression coverage for trailing invalid characters.
- Preserve support for valid version formats and Go toolchain output.

## Verification

go test -count=1 ./...
go vet ./...
gofmt -l .

Manual negative case:

go run . list --go-version=1.24invalid
echo %ERRORLEVEL%

Expected result: a parsing error and a nonzero exit code.

## Note

Issue creation is restricted in this repository, so I am submitting this focused PR directly for maintainer review.

Use the **Changes** section only if your branch already contains those code and test changes.

- Replace loose regex matching with strictGoVersionPattern anchored to input boundaries
- Reject invalid version strings like '1.24x', 'invalid.ver', and 'abc1.24'
- Add TestNormalizeGoVersionStrictRejection regression tests
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