-
-
Notifications
You must be signed in to change notification settings - Fork 233
fix: Add common License filenames #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds common License file names (which usually don't come with extensions) to the list of searchable files.
WalkthroughThe license file lookup functionality in the Updates controller is extended to recognize license files without file extensions. Two additional filename candidates ('LICENCE' and 'LICENSE') are added to the existing search array. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
modules/system/controllers/Updates.php (1)
181-200:⚠️ Potential issue | 🟡 Minor
getPluginMarkdownFileapplies Markdown parsing to all files regardless of extension.When this method processes the newly added extensionless
LICENCE/LICENSEfiles (which are typically plain text),Markdown::parse()on line 194 may produce garbled HTML output. A minimal guard could skip Markdown parsing for files without a.mdextension:Sketch of a conditional parse
$contents = File::get($path . '/'.$file); - /* - * Parse markdown, clean HTML, remove first H1 tag - */ - $contents = Markdown::parse($contents); + if (pathinfo($file, PATHINFO_EXTENSION) === 'md') { + $contents = Markdown::parse($contents); + } else { + $contents = '<pre>' . e($contents) . '</pre>'; + } $contents = Html::clean($contents); $contents = preg_replace('@<h1[^>]*?>.*?<\/h1>@si', '', $contents, 1);This would prevent plain-text license files from being misinterpreted as Markdown. Given the PR author plans a follow-up for this, consider addressing it now or as an immediate next step.
🧹 Nitpick comments (1)
modules/system/controllers/Updates.php (1)
130-130: Consider adding.txtvariants and note the Markdown-parsing concern.Common license filenames also include
LICENSE.txt,LICENCE.txt, and their lowercase variants. You may want to add those for completeness.More importantly, extensionless (and
.txt) license files are plain text, butgetPluginMarkdownFile()on line 194 unconditionally runsMarkdown::parse()on the contents. This can mangle plain-text formatting (e.g., lines with*,_, or indentation being reinterpreted). I see from the PR description you're aware of this and plan a follow-up — just flagging it here for visibility.Suggested expanded list
- $licenceFiles = ['LICENCE.md', 'licence.md', 'LICENSE.md', 'license.md', 'LICENCE', 'LICENSE']; + $licenceFiles = ['LICENCE.md', 'licence.md', 'LICENSE.md', 'license.md', 'LICENCE.txt', 'licence.txt', 'LICENSE.txt', 'license.txt', 'LICENCE', 'LICENSE'];
Small thing I just noted when I went to prepare a new plugin for release: The Winter CMS backend doesn't check the filenames "LICENSE" and "LICENCE" when providing plugin details. This PR adds them.
(I didn't check how common these are, but I have seen quite a bit of repositories — including my own — that omit the filename extension.)
Nota bene: We might want to also refactor the Markdown-parsing step since extensionless files usually are supposed to be rendered as plain text. That is less of an issue, though, but if you're up to it, I can draft up another PR quickly.
Summary by CodeRabbit