fix: reject non-YAML extensions for --sqlconfig flag#747
Open
dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
Open
fix: reject non-YAML extensions for --sqlconfig flag#747dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
Conversation
1908b0b to
2a0995b
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses confusing behavior where --sqlconfig accepts non-YAML extensions (e.g., .json) but still writes YAML content, by validating the config filename extension at internal/config.SetFileName() time.
Changes:
- Add extension validation in
SetFileName()to reject non-.yaml/.ymlextensions (while allowing extensionless filenames). - Add unit test coverage for accepted/rejected extensions.
- Update README documentation for
--sqlconfigcustom configuration files.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/config/config.go | Enforces YAML-only extensions (and rejects other extensions) for config filenames passed into the config subsystem. |
| internal/config/config_test.go | Adds coverage ensuring .json/.toml are rejected and .yaml/.yml are accepted. |
| README.md | Documents the expected YAML extension requirements for custom config files via --sqlconfig. |
2a0995b to
8461abd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sqlcmd --sqlconfig config.jsonsilently creates a JSON-named file but writes YAML content, leading to confusing behavior when users reference it later.Fixes #690, Fixes #597
Root Cause
No extension validation in
config.SetFileName().Solution
SetFileName()before proceeding.yamlor.yml(extensionless files like the default~/.sqlcmd/sqlconfigare still allowed)checkErr(consistent with existing error patterns in this package)Changes
internal/config/config.goSetFileNameinternal/config/config_test.goREADME.mdTesting
go build ./cmd/modernpassesgo test ./internal/config/...passesTestSetFileName_RejectsNonYAMLExtensionverifies.json/.tomlrejected and.yaml/.ymlaccepted