Skip to content

fix: reject trailing newlines in preset IDs - #5188

Merged
mnriem merged 1 commit into
github:mainfrom
mnriem:mnriem-preset-id-validation
Oct 29, 2026
Merged

mnriem merged 1 commit into
github:mainfrom
mnriem:mnriem-preset-id-validation

Conversation

@mnriem

@mnriem mnriem commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Description

Reject preset IDs containing trailing newlines by validating the entire string with re.fullmatch. This preserves the existing lowercase alphanumeric-and-hyphen format and prevents malformed IDs from passing manifest validation.

Add regression coverage for trailing and embedded newlines, whitespace, path separators, empty IDs, and valid IDs.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

Used this worktree's own virtual environment instead of the uv run commands above, as recommended by CONTRIBUTING.md:

  • uv sync --extra test - passed.
  • .venv/bin/python -m pytest tests/specify_cli/presets/test_manifest.py -q -k 'pack_id_format' before the fix - failed as expected: 1 failed, 12 passed; the trailing-newline case was accepted.
  • .venv/bin/python -m pytest tests/specify_cli/presets -q after the fix - passed: 758 passed.
  • LC_ALL=en_US.UTF-8 .venv/bin/python -m pytest tests -q - passed: 13,673 passed, 130 skipped, 63 warnings.
  • .venv/bin/specify --help - passed.
  • git diff --check - passed.

Sample-project and agent slash-command testing are not applicable to this manifest-validation fix.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: GitHub Copilot using GPT-6.1 Sol (model ID: gpt-6.1-sol, runtime-default reasoning settings) assessed the validation defect, authored the fix and tests, ran automated validation, and prepared the commit and this PR on behalf of @mnriem. Execution was autonomous within user-approved scope; no human line-by-line review or manual testing is claimed.

Require the entire preset ID to match the allowed character set and cover valid and malformed IDs with regression tests.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI auto review requested due to automatic review settings October 29, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active issues are identified, and the change is narrowly focused on complete preset-ID validation with corresponding regression coverage.

No open issues 🎉

What changed in this PR

This pull request hardens preset manifest validation so preset IDs must fully match the lowercase alphanumeric-and-hyphen format, rejecting trailing and embedded newlines.

Changes:

  • Replaced anchored re.match validation with re.fullmatch.
  • Added regression coverage for newlines, whitespace, path separators, empty IDs, and invalid casing.
  • Added positive coverage for valid preset IDs.
File Description
tests/​specify_cli/​presets/​test_manifest.py Adds negative and positive regression coverage for preset ID formats.
src/​specify_cli/​presets/​_manifest.py Enforces complete-string validation for preset IDs.

Review effort: Lite (auto)

@mnriem
mnriem merged commit 03bba71 into github:main Oct 29, 2026
16 checks passed
@mnriem
mnriem deleted the mnriem-preset-id-validation branch October 29, 2026 16:39
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