fix: ensure idempotent project-relative path rewriting in CommandRegistrar - #4553
Open
darion-yaphet wants to merge 1 commit into
Open
fix: ensure idempotent project-relative path rewriting in CommandRegistrar#4553darion-yaphet wants to merge 1 commit into
darion-yaphet wants to merge 1 commit into
Conversation
…strar
Replace the fragile pattern of three sequential string replacements followed by three re.sub calls and trailing `.replace(".specify/.specify/", ".specify/")` / `.replace(".specify.specify/", ".specify/")` patches in CommandRegistrar.rewrite_project_relative_paths.
Consolidate the transformation into a unified regex match callback that:
- Inspects matched path prefixes (`.specify/`, `../`, `./`, `/`, or bare)
- Naturally guards already-normalized `.specify/` paths from double-prefixing
- Directs parent relative references (`../`) to root `.specify/<target>/`
- Preserves extension-local script scoping when extension_id is provided
- Expands boundary delimiters to include Markdown brackets, parentheses, braces, angle brackets, and backticks
Add unit tests in tests/test_extensions.py covering repeated passes for idempotency, markdown enclosure delimiters, and edge-case inputs.
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.
Description
used
.replace(".specify/.specify/", ".specify/").replace(".specify.specify/", ".specify/")as an ad-hoc post-processing fix. This "patch-on-patch" design wasfragile, caused redundant string scanning, and risked regressions when paths were processed multiple times.
source and eliminating the need for subsequent
.replace()corrections.3. Deterministic routing: Parent-relative paths (
../) consistently route to root.specify/<target>/, while top-level / relativescripts/preserveextension-local scoping when
extension_idis supplied.4. Expanded delimiters: Recognizes common Markdown punctuation enclosures such as brackets
[], parentheses(), braces{}, angle brackets<>, quotes,and backticks.
Testing