GLM-5.3 · Balanced
enhance-embed-url-handling-and-validation-system-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
- 2 of 12
- Comments published
- 5
- Comments matching a bug
- 2
- Comments not matching
- 3
- Cost of this PR
- $1.139
Published comments (5)
Invalid `<%- end if %>` tag in embed template causes SyntaxError on every render — The `<%- end if %>` ERB tag compiles to a trailing `if` modifier with no condition after `end` — stdlib ERB joins compiled segments with `;` and the Rails Erubis handler likewise appends `;` after the tag body, producing invalid Ruby (`end if;`) and a SyntaxError when ActionView compiles the template. Every `/embed/best` request for a URL that already has a topic returns a 500, so the embed widget can never render comments (the controller specs never render views, so this is uncaught).
poll_feed crashes on Ruby 2.0 and nil content: String#scrub is undefined — `i.content.scrub` raises NoMethodError: `String#scrub` does not exist on Ruby 2.0.0 (the version this project runs and tests on per `.travis.yml`; the method was added in Ruby 2.1), and `i.content` is nil for feed items that lack a content element. The exception aborts `poll_feed` at the first item — with `sidekiq_options retry: false` the hourly job fails silently forever, so no feed items are ever imported and the RSS branch of `TopicRetriever#perform_retrieve` can never succeed (the specs stub `poll_feed`, so this path is untested).
NOT NULL default column add rewrites posts table under ACCESS EXCLUSIVE lock — `add_column :posts, :cook_method, :integer, default: 1, null: false` forces a full table rewrite under an ACCESS EXCLUSIVE lock on PostgreSQL 9.x (the no-rewrite optimization for constant defaults only landed in PG 11), blocking all reads and writes on the forum's largest, hottest table for the duration of the copy during deploy. Add the column as nullable with the default, backfill existing rows in batches, then attach the NOT NULL constraint.
Protocol-relative URLs (//host/...) are broken by absolutize_urls — Protocol-relative URLs such as `//cdn.example.com/img.jpg` satisfy `href.start_with?('/')`, and `href.sub(/^\/+/, '')` strips both slashes, so the URL is rewritten to `http://<embed-host>/cdn.example.com/img.jpg`. Imported articles that use protocol-relative links or images (common in RSS/WordPress feeds and CDN assets) get every such link broken.
Double HTML-unescaping corrupts escaped HTML in imported feed items — `CGI.unescapeHTML` decodes the feed item's HTML a second time: SimpleRSS already returns XML-unescaped HTML, so content-level escapes such as `<div>` in an article's code sample become literal `<div>` markup, which is then stored via the `raw_html` cook_method and rendered with `raw post.cooked`. Every imported article containing escaped HTML examples or entity-encoded text is silently corrupted (and escaped tags become live tags) — drop the `CGI.unescapeHTML` call and pass `i.content` through as-is.