Validate build output permalinks#63
Conversation
|
Warning Review limit reached
More reviews will be available in 55 minutes and 38 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR tightens build-time permalink handling to prevent unsafe output paths and to detect permalink collisions early, reducing the chance of parallel writers overwriting the same output file. It also adds tests and documents the permalink constraints.
Changes:
- Add build-time detection of duplicate permalinks and fail the build when duplicates exist.
- Validate permalink path segments before computing output file paths (rejecting unsafe segments like
./..). - Add unit tests for duplicate permalinks and unsafe permalink segments; document permalink constraints in the content docs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/Unit/Console/BuildCommandTest.php | Adds regression tests for duplicate permalinks and unsafe permalink segments causing build failure. |
| src/Console/BuildCommand.php | Implements duplicate-permalink detection and output path validation for permalinks. |
| docs/content.md | Documents new permalink constraints in front matter docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private function duplicatePermalinks(array $fileToPermalink): array | ||
| { | ||
| $sourcesByPermalink = []; | ||
| foreach ($fileToPermalink as $source => $permalink) { | ||
| $sourcesByPermalink[$permalink][] = $source; | ||
| } | ||
|
|
||
| return array_filter( | ||
| $sourcesByPermalink, | ||
| static fn (array $sources): bool => count($sources) > 1, | ||
| ); | ||
| } |
| $duplicatePermalinks = $this->duplicatePermalinks($fileToPermalink); | ||
| if ($duplicatePermalinks !== []) { |
| $segments = explode('/', trim($permalink, '/')); | ||
| foreach ($segments as $segment) { | ||
| if ($segment === '' || $segment === '.' || $segment === '..') { | ||
| throw new RuntimeException(sprintf('Permalink "%s" contains an unsafe path segment.', $permalink)); | ||
| } | ||
| } |
Summary
Tests