FIX: crash in Admin::PluginsController when plugin has nil commit URL path (#35186)

The `discourse_owned?` method in `lib/plugin/instance.rb` was calling
`.split` on `parsed_commit_url.path` without checking if the path could
be nil. This caused a 500 error on `/admin/plugins` when any plugin had
a commit URL that parsed successfully but returned a nil path (e.g.,
plugins without a git remote configured).

Added a nil check for `parsed_commit_url.path` to gracefully handle this
edge case and prevent the crash. Also added a test case to verify the
method returns false when the parsed URL has a nil path.
This commit is contained in:
ducks
2025-10-06 14:39:23 +00:00
committed by GitHub
parent a3283d3b8e
commit 6971fffa32
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -624,7 +624,7 @@ class Plugin::Instance
def discourse_owned?
return false if commit_hash.blank?
parsed_commit_url = UrlHelper.relaxed_parse(self.commit_url)
return false if parsed_commit_url.blank?
return false if parsed_commit_url.blank? || parsed_commit_url.path.blank?
github_org = parsed_commit_url.path.split("/")[1]
(github_org == "discourse" || github_org == "discourse-org") &&
parsed_commit_url.host == "github.com"