DeepSeek V4.1 Flash · Heavy

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

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

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
1 of 4
Comments published
13
Comments matching a bug
1
Comments not matching
12
Cost of this PR
$0.450

Published comments (13)

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

Migration dereferences nil when embed_category or uncategorized row is missing — Forums that never overrode `embed_category` have no such `SiteSetting` row, so `execute(...)[0]['id']` raises `NoMethodError` and the migration cannot run. Guard with `.first` and fall back to `SiteSetting.uncategorized_category_id`.

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

Migration inserts embeddable hosts without normalization or SQL escaping — Legacy values with a scheme or path survive verbatim, so `record_for_host` never matches the bare host and embedding silently breaks after upgrade. Normalize each value like the model does and use a quoted insert so a host containing a quote cannot abort the migration.

highbugapp/models/embeddable_host.rb:17

EmbeddableHost lookup fails when referer host has uppercase letters — A referer such as `http://EvilTrout.com/page` keeps its case, so `where("lower(host) = ?", host)` never matches the configured host and the embed frame is rejected. Downcase the argument too.

highbugapp/assets/javascripts/discourse/models/store.js.es6:196-199

Guard `_hydrateEmbedded` against non-array `_ids` values — The regex now matches every `_ids` key, so a null or non-array value makes `obj[k].map` throw and breaks the whole `store.find`/`findAll` for that type. Guard with `Array.isArray(obj[k])` and leave the key untouched otherwise.

mediumbugapp/controllers/admin/embeddable_hosts_controller.rb:10-17

Missing nil check on embeddable host lookup returns 500 — A stale or already-deleted id (double-click on delete, two admins editing) makes `host.host = ...` or `host.destroy` raise `NoMethodError` and answer 500. Use `find_by!` or raise `Discourse::NotFound` so a missing record returns 404.

mediumperformanceapp/controllers/embed_controller.rb:61

Uncached embeddable host lookup runs on every embed request — Each embedded page view now adds an uncached SQL round trip, and the `lower(host) = ?` predicate blocks any index on `host`. Cache the host list and compare in Ruby, or store hosts downcased in an indexed column.

mediumbugdb/migrate/20150818190757_create_embeddable_hosts.rb:9-11

Migration resolves numeric embed_category by name, losing category — A stored numeric id fails the name join, so `category_id` resolves to 0 and every host falls back to `uncategorized_category_id`, losing the category. Resolve by id when the value is numeric and by name otherwise, mirroring `TopicCreator#find_category`.

mediumbugapp/models/topic_embed.rb:36-43

Embedded posts lose category when EmbeddableHost lookup misses — When `record_for_host` returns `false` for an unparseable URL or `nil` for no match, the embedded topic is created with `category: nil` and lands in uncategorized, where it previously went to the configured category. Fall back to `SiteSetting.embed_category`, and downcase the argument in `record_for_host`.

mediumbugspec/models/topic_spec.rb:1403-1405

Vacuous expandable_first_post? test no longer exercises embeddable host — `expandable_first_post?` no longer consults embeddable hosts, and this example sets neither `embed_truncate` nor the `has_topic_embed?` stub, so it passes on defaults and cannot fail for the reason its name claims. Delete it; the no-embed case is already covered in the nested block.

mediumbugapp/models/embeddable_host.rb:5-8

before_validation crashes on nil host instead of failing validation — A nil host from a missing `params[:embeddable_host][:host]` makes `self.host.sub!` raise `NoMethodError` and answer 500, so `validates_format_of :host` never reports it. Assign through `self.host.to_s.sub(...)` to return a 422 instead.

mediumbugapp/assets/javascripts/discourse/models/store.js.es6:196-201

Plural embedded hydration drops unresolved ids and maps null — When the side-loaded key does not match `pluralize(subType)` or is missing, every `_lookupSubType` returns undefined, the raw ids are lost, and the property becomes `[undefined, ...]`. Delete and replace the ids key only when the lookup resolved, otherwise keep the original.

mediumbugapp/assets/javascripts/discourse/models/store.js.es6:196-201

Plural `*_ids` hydration stores undefined for missing records — `_lookupSubType` returns undefined for ids missing from the side-loaded collection, so `[undefined, ...]` is stored and consumers like `embeddable-host`'s `host.category.id` throw a TypeError. Filter unresolved ids before assigning.

mediumbugtest/javascripts/models/store-test.js.es6:111-117

Test requests fruit 2 but pretender fixture returns fruit 1's data — The pretender handler for `/fruits/:id` in `create-pretender.js.es6` hardcodes `fruits[0]` and ignores the requested id, so these assertions verify apple's fixture and would pass even if the store mangled the id. Look the record up by `request.params.id` or request fruit 1.

Gold bugs found (1)

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.

Gold bugs missed (3)

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.
highEmbeddableHost's host format validation only accepts TLDs of 2-5 letters, so admins cannot add embeddable hosts on longer TLDs like example.technology.