Claude Sonnet 5.5 · Balanced

feature-can-edit-category-host-relationships-for-embedding-discourse-cursor

Discourse · Ruby · M · 100–299 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 4
Comments published
7
Comments matching a bug
3
Comments not matching
4
Cost of this PR
$0.636

Published comments (7)

highbugdb/migrate/20150818190757_create_embeddable_hosts.rb:9-16

Migration crashes when embed_category or uncategorized_category_id row is missing — On a default install the `embed_category` row is absent, so `[0]` is nil and the migration raises NoMethodError, blocking the deploy. Fetch `.first` into a variable and fall back to 0 when nil, for both the `embed_category` and `uncategorized_category_id` lookups.

highbugdb/migrate/20150818190757_create_embeddable_hosts.rb:22-26

Migration inserts unnormalized embeddable hosts with unescaped raw SQL — The raw INSERT bypasses the model's `before_validation`, so legacy values like `http://discourse.org` are stored with scheme or path and `record_for_host` never matches them, breaking embedding after upgrade. Normalize each value (strip scheme and path, downcase, skip blanks) and quote it before inserting.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation callback raises NoMethodError when host is nil — A request with a missing `host` raises NoMethodError and returns a 500 instead of a validation error. Skip the `sub!` calls when `host` is blank, or assign a non-mutating `sub` result, so `validates_format_of` reports the problem.

mediumbugapp/controllers/admin/embeddable_hosts_controller.rb:9-18

update and destroy raise NoMethodError (500) for unknown host ids — An unknown or already-deleted id makes `update` and `destroy` dereference nil, returning a 500 instead of a 404. Use `EmbeddableHost.find` or raise `Discourse::NotFound` when nil, and check that the nested `params[:embeddable_host]` exists in `save_host`.

mediumbugapp/models/embeddable_host.rb:10-18

record_for_host fails to downcase host, rejecting registered hosts with uppercase — Registered hosts are rejected when the incoming URL has uppercase characters, because `record_for_host` compares `lower(host)` against a non-downcased `uri.host`. Compare with `host.downcase` instead.

mediumbugapp/models/embeddable_host.rb:2-18

Host validation accepts ports that record_for_host can never match — A host saved with a port can never match, because `record_for_host` compares only `uri.host`, so embedding silently fails for it. Remove the port from the validation regex, or match `host:port` when `uri.port` is non-default.

mediumbugapp/assets/javascripts/admin/components/embeddable-host.js.es6:36-40

Host category set from local categoryId instead of server-saved category_id — For a new host with no chosen category, the local `categoryId` is null while the server stores the uncategorized category, so the badge is empty until reload. Set `category` from the `category_id` in the saved response instead of `categoryId`.

Gold bugs found (3)

highThe migration reads execute(...)[0]['id'] for embed_category without checking for an empty result, so installs without that setting stored crash the migration instead of falling back to the uncategorized category.
mediumAfter saving a host, the component overwrites its category with findById(categoryId); when no category was chosen this is null even though the server saved the uncategorized category, so the row shows no category until reload.
highHosts saved with a port (allowed by the validation regex) are stored as host:port, but lookup compares only URI.host, so those configured hosts never match and embedding fails for them.

Gold bugs missed (1)

highEmbeddableHost's host format validation only accepts TLDs of 2-5 letters, so admins cannot add embeddable hosts on longer TLDs like example.technology.