Enhance embed URL handling and validation system#4
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f8aed295a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| require 'ruby-readability' | ||
|
|
||
| opts = opts || {} | ||
| doc = Readability::Document.new(open(url).read, | ||
| tags: %w[div p code pre h1 h2 h3 b em i strong a img], |
There was a problem hiding this comment.
Require open-uri before calling open(url)
TopicEmbed.import_remote calls open(url).read without requiring open-uri. In a Sidekiq worker or task that hasn't already loaded open-uri, this will invoke Kernel#open on a string like http://... and raise Errno::ENOENT, so embed retrieval and Disqus imports can fail immediately depending on load order. Adding require 'open-uri' (or using URI.open) in this method would make the fetch reliable regardless of what other code has been loaded.
Useful? React with 👍 / 👎.
| fragment.css('a').each do |a| | ||
| href = a['href'] | ||
| if href.present? && href.start_with?('/') | ||
| a['href'] = "#{prefix}/#{href.sub(/^\/+/, '')}" | ||
| end |
There was a problem hiding this comment.
Handle non-root relative URLs in import
absolutize_urls only rewrites URLs that start with /, so relative links like href="images/foo.png" or src="../img.png" remain unchanged. When the post is rendered on the Discourse domain, those URLs resolve against the forum host instead of the source site, breaking links/images for many RSS/HTML feeds that use document-relative paths. Consider using URI.join with the source URL for all relative paths, not just root-relative ones.
Useful? React with 👍 / 👎.
Test 4
Replicated from ai-code-review-evaluation/discourse-cursor#4