Keep Lexxy's engine from changing applications that don't use it - #1262
jorgemanrubia wants to merge 2 commits into
Conversation
Rails versions that include Lexxy load it in every Action Text application. Two parts of Lexxy's engine then changed applications that use Trix, or no editor at all: - The sanitizer initializer replaced the tags and attributes an application allows. On a Rails version that includes Lexxy, Action Text already allows Lexxy's markup, so leave the lists to the application there. Elsewhere, keep adding Lexxy's markup to the lists, as before. - Blob#as_json raised without URL options and ignored only, except, and root. Skip the preview fields without URL options, and respect those serialization options.
There was a problem hiding this comment.
🟡 Changes recommended
Explicit empty only allowlists must exclude preview fields.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR prevents Lexxy from overriding sanitizer settings and makes preview blob JSON serialization safer.
Changes:
- Conditionally applies sanitizer customization.
- Respects URL,
only,except, androotserialization options. - Adds sanitizer and blob regression tests.
Review finding: Moderate — blob.as_json(only: []) incorrectly includes preview fields.
File summaries
| File | Description |
|---|---|
test/actiontext/sanitizer_lists_test.rb |
Tests sanitizer behavior across configurations. |
test/actiontext/blob_test.rb |
Tests preview JSON serialization options. |
lib/lexxy/engine.rb |
Gates sanitizer customization. |
lib/active_storage/blob_with_preview_url.rb |
Updates preview JSON handling. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| only = Array(options[:only]).map(&:to_s) | ||
| except = Array(options[:except]).map(&:to_s) | ||
|
|
||
| (only.empty? || only.include?(field)) && except.exclude?(field) |
There was a problem hiding this comment.
🤖 Fixed in 1f017ae. The preview fields now follow Active Model: a supplied only, including an empty array, is an allowlist and takes precedence over except. as_json(only: []) returns no preview fields, and as_json(only: [ :id, :url ], except: :url) returns id and url. Both cases are in the regression tests.
Review found that Blob#as_json added preview fields for only: [] and applied except alongside only, unlike Active Model. The sanitizer tests also depended on which Rails was bundled, and asked for load_defaults that Rails 8.0 doesn't have.
1f017ae to
91620c9
Compare
Make Lexxy the default Action Text editor for new applications makes Action Text load Lexxy in every application. That includes applications that use Trix, and ones that don't use rich text at all. Two parts of Lexxy's engine change those applications:
ActionText::ContentHelper.allowed_tagsandallowed_attributeswith its own widened lists. An application that restricts those lists gets Lexxy's tables, media andstyleattributes added back.Blob#as_jsonaddspreviewableand a previewurlto every previewable blob. WithoutActiveStorage::Current.url_optionsit raises, and it ignoresonly,exceptandroot.What changes
to_prepare, and making Lexxy stop appending broke 8 of its tests.Blob#as_jsonnow:onlyandexcept: a suppliedonly, even an empty one, is an allowlist and takes precedence overexcept;Tests
The new tests fail on
mainand pass here. They cover the sanitizer lists, using throwaway apps in subprocesses with lazy and eager loading, andBlob#as_json. Locally:USE_RAILS_WITHOUT_ACTION_TEXT_ADAPTER=trueThe Rails 8.1 run needed
json < 3pinned locally, because json 3.0 breaks Rails 8.1.3.1.CI
Rails 8.1 job: it fails because json 3.0 breaks Rails 8.1.3.1's
ActiveSupport::JSON.decode. It fails the same way onmainand on other open PRs.Rails main job: It passes. The first run hit one error and the rerun passed: 98 runs, 0 failures, 0 errors. The error was
PageRefreshesTest#test_prompts_work_after_page_refresh, which times out waiting for the mention prompt after a Turbo page refresh. That test is flaky without this change. Run on its own:It passed in both full local suite runs on this branch, and nothing here touches prompts or page refreshes.
This is independent of Depend on railties instead of rails and Respect config.action_text.editor on Rails that include Lexxy. The Rails PR needs all three.