Skip to content

Fix(validation): Normalize profile names by trimming whitespace#57

Closed
sameerchore wants to merge 3 commits into
OpenVTC:mainfrom
sameerchore:fix/trim-profile-name-validation
Closed

Fix(validation): Normalize profile names by trimming whitespace#57
sameerchore wants to merge 3 commits into
OpenVTC:mainfrom
sameerchore:fix/trim-profile-name-validation

Conversation

@sameerchore
Copy link
Copy Markdown
Contributor

Fix: Normalize profile name validation by trimming whitespace

Description

What was wrong

The validate_profile_name function in openvtc-lib/src/config/public_config.rs did not normalize input before validation:

  • Strings like " default " were not recognized as "default", causing unexpected rejections.
  • Whitespace-only inputs (e.g., " ") bypassed the empty check (since " ".is_empty() is false) and were evaluated by the character validation, leading to inconsistent error messages.
  • The empty check ran after the character validation, meaning an empty string would hit the character check first — a logic ordering issue.

What was changed

  • Input is now trimmed using .trim() before any validation logic runs.
  • The empty check runs first on the trimmed value, ensuring whitespace-only and empty inputs are caught immediately with a clear error message.
  • Character validation is then applied to the trimmed value, so leading/trailing whitespace no longer causes false rejections.
  • Added 3 new integration tests to cover the new trimming behavior.

Impact

  • Prevents invalid edge cases: " default " now correctly resolves as "default".
  • Improves consistency: Whitespace-only inputs get a clear, specific error message ("Profile name cannot be empty or contain only whitespace").
  • Fixes logic ordering: Empty/whitespace check now runs before character validation.

Advantages

Aspect Before After
" default " Rejected as invalid chars Accepted as "default"
" " (spaces) Misleading "invalid chars" error Clear "empty or whitespace" error
"" (empty) Caught, but after char check Caught immediately
" my-profile " Rejected Accepted
"my-profile" Accepted Accepted (no change)

Risk

Note

Minimal — This change only affects edge cases involving leading/trailing whitespace. All previously valid profile names continue to work identically. The only behavioral change is that whitespace-padded inputs are now accepted (after trimming) rather than rejected.

Testing

  • Existing tests pass unchanged (valid names, empty, spaces-in-middle, special chars).
  • 3 new tests added:
    • whitespace_only_profile_name_rejected" ", " ", "\t" → error
    • padded_default_profile_name_accepted" default ", " default " → ok
    • padded_valid_profile_name_accepted" my-profile ", " Profile123 " → ok

Run tests with:

cargo test --test profile_validation

Result:

test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.65s

Signed-off-by: Sameer Chore <sameerchore5@gmail.com>
@sameerchore sameerchore requested a review from a team as a code owner April 25, 2026 06:07
@sameerchore sameerchore force-pushed the fix/trim-profile-name-validation branch 5 times, most recently from ec4b590 to 9d740f3 Compare April 25, 2026 09:49
Signed-off-by: Sameer Chore <sameerchore5@gmail.com>
…argo audit

Signed-off-by: Sameer Chore <sameerchore5@gmail.com>
@sameerchore
Copy link
Copy Markdown
Contributor Author

Hi @stormer78,

Could you please take a look at this PR when you get a chance? I believe the changes are in good shape, but I’m happy to make any further updates if needed.

If everything looks good from your side, we can proceed for further procedure or updations if required.
Thanks!

stormer78 added a commit that referenced this pull request May 5, 2026
Folds in @sameerchore's PR #57. `validate_profile_name` now trims
leading/trailing whitespace before validating, so `" default "` is
treated as `"default"`, and the empty/whitespace check runs *before*
the character validation so a whitespace-only input ("   ") gets a
clear "cannot be empty or contain only whitespace" error instead of
the confusing "Invalid profile name '   '" the alphanumeric check
used to produce.

Adds the three integration tests from the PR:
- whitespace_only_profile_name_rejected
- padded_default_profile_name_accepted
- padded_valid_profile_name_accepted

Closes #57.

Co-authored-by: Sameer Chore <sameerchore5@gmail.com>
Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
stormer78 added a commit that referenced this pull request May 5, 2026
Records the substantive folds from PRs #57 (profile-name validation),
#51 (Windows AppData + PathBuf cross-platform paths, closes #47), and
#34 (SecuredConfig tagged-variant downgrade defence + intent gate)
under v0.2.0's "Post-release deep-review pass". Adds a "Community
contributions" subsection summarising each fold with author credit.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
@stormer78
Copy link
Copy Markdown
Contributor

Thank you @sameerchore — folded into the v0.2.0 release branch as commit ae7fd72 with Co-authored-by: attribution to keep your name on the contribution. Your trim + reorder + the three integration tests landed unchanged; only the path translated from openvtc-lib/ to openvtc-core/ (workspace was renamed mid-flight in #58). Tracked under the "Community contributions" section of CHANGELOG.md.

Closing in favour of #58.

@stormer78 stormer78 closed this May 5, 2026
@stormer78 stormer78 mentioned this pull request May 5, 2026
7 tasks
stormer78 added a commit that referenced this pull request May 5, 2026
Folds in @sameerchore's PR #57. `validate_profile_name` now trims
leading/trailing whitespace before validating, so `" default "` is
treated as `"default"`, and the empty/whitespace check runs *before*
the character validation so a whitespace-only input ("   ") gets a
clear "cannot be empty or contain only whitespace" error instead of
the confusing "Invalid profile name '   '" the alphanumeric check
used to produce.

Adds the three integration tests from the PR:
- whitespace_only_profile_name_rejected
- padded_default_profile_name_accepted
- padded_valid_profile_name_accepted

Closes #57.

Co-authored-by: Sameer Chore <sameerchore5@gmail.com>
Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
stormer78 added a commit that referenced this pull request May 5, 2026
Records the substantive folds from PRs #57 (profile-name validation),
#51 (Windows AppData + PathBuf cross-platform paths, closes #47), and
#34 (SecuredConfig tagged-variant downgrade defence + intent gate)
under v0.2.0's "Post-release deep-review pass". Adds a "Community
contributions" subsection summarising each fold with author credit.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
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.

2 participants