Skip to content

Add pattern validation to spec.name in JSON schema #29

@Fieldnote-Echo

Description

Problem

The name field in schema/spec-schema.json (line 7) only enforces minLength: 1:

"name": { "type": "string", "minLength": 1 }

This accepts spaces, newlines, control characters, emoji, and other values that break directory creation and pyproject.toml generation. The CLI has ad-hoc guards for /, \, and leading . but those only run in certain code paths — the schema is the single source of truth.

Fix

Add a pattern constraint to the name property in schema/spec-schema.json. A reasonable pattern following PyPI/PEP 508 naming conventions:

"name": { "type": "string", "minLength": 1, "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$" }

The license field on line 10 already uses a pattern — this follows the same approach.

Tests

Add test cases in tests/test_spec.py covering:

  • Valid names: my-project, foo_bar, a, my.pkg
  • Invalid names: "", "has spaces", "../traversal", "-leading-dash", "trailing-", "new\nline"

Files to change

  • schema/spec-schema.json
  • tests/test_spec.py

Ref

DEBT.md item D3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions