1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
mastodon/spec
Calvin Lee 9eb30dfb1c Sanitize MathML in post content
Summary:
-------
This commit correctly sanitizes incoming MathML according to [FEP-dc88].
Instead of completely removing MathML nodes, it replaces them with their
LaTeX or plain-text representation, so that the mathematics can be read
in some form by mastodon users.

Test Plan:
----------
```
$ RAILS_ENV=test bundle exec rspec spec/lib/sanitize_config_spec.rb -f d
Run options: exclude {:type=>#<Proc: ./spec/rails_helper.rb:79>}

Randomized with seed 58854

Sanitize::Config
  ::MASTODON_STRICT
    sanitizes math blocks to LaTeX
    converts h1 to p strong
    removes "translate" attribute with invalid value
    removes a without href
    removes a without href and only keeps text content
    math sanitizer falls back to plaintext
    keeps ul
    prefers latex
    removes a with unparsable href
    keeps start and reversed attributes of ol
    removes a with unsupported scheme in href
    keeps a with translate="no"
    keeps a with href
    keeps a with supported scheme and no host
    does not re-interpret HTML when removing unsupported links
    sanitizes math to LaTeX

Finished in 0.17323 seconds (files took 3.28 seconds to load)
16 examples, 0 failures

Randomized with seed 58854

```

observed 100% code coverage of `lib/sanitize_ext/sanitize_config.rb`.

Ran mastodon locally, and fetched [reference post][nyancat] and observed
that math was converted to plaintext form (and was not missing).

[FEP-dc88]: https://codeberg.org/fediverse/fep/src/branch/main/fep/dc88/fep-dc88.md
[tracking]: https://codeberg.org/fediverse/fep/issues/161
[socialhub]: https://socialhub.activitypub.rocks/t/fep-dc88-formatting-mathematics/3564
[nyancat]: https://nyan.network/notice/Aa4IvnBVHysWswRX1s

Related Discussion:
-------------------

Please see [FEP-dc88], the [FEP tracking issue][tracking] and
[FEP forum discussion][socialhub] for more information.

Fixes mastodon/mastodon#26943
2024-04-25 10:16:39 +00:00
..
chewy Add new public status index (#26344) 2023-08-24 16:40:04 +02:00
config/initializers/rack Use unchanging github links in docs/comments (#29545) 2024-03-11 15:14:55 +00:00
controllers Remove caching in cache_collection (#29862) 2024-04-08 13:46:13 +00:00
fabrication Ensure unique values in fabricators (#29515) 2024-03-11 08:53:24 +00:00
fabricators Use fabrication sequence in domain values (#29895) 2024-04-11 08:59:01 +00:00
features Move OAuth flow tests from feature tests to system tests (#29837) 2024-04-05 16:52:05 +00:00
fixtures Add end-to-end test for OCR in media uploads (#29148) 2024-02-08 19:13:44 +00:00
generators Fix flaky tests related to file creation (#28248) 2023-12-06 22:22:25 +00:00
helpers Separate methods for theme style and meta color tags (#29802) 2024-04-05 09:52:43 +00:00
lib Sanitize MathML in post content 2024-04-25 10:16:39 +00:00
locales Replace i18n view spec with helper spec (#24966) 2023-05-15 17:25:04 +02:00
mailers Add stub for trending tags in user mailer spec (#29850) 2024-04-05 07:48:07 +00:00
models Use enum-generated scopes/queries for BulkImport (#29975) 2024-04-18 10:13:35 +00:00
policies Rename and refactor User#confirm! to User#mark_email_as_confirmed! (#28735) 2024-01-15 18:04:58 +00:00
presenters Remove unneeded settings cleanup from specs (#28425) 2023-12-19 15:17:22 +00:00
requests Add read:me OAuth 2.0 scope, allowing more limited access to user data (#29087) 2024-04-23 11:47:00 +00:00
routing Enable Style/FrozenStringLiteralComment for specs (#23790) 2023-02-22 09:55:31 +09:00
search/models/concerns/account Use enum-generated public_visibility scope on Status (#28156) 2024-03-14 09:31:57 +00:00
serializers Add max_pinned_statuses to instances serializer and api response (#29441) 2024-04-02 13:54:11 +00:00
services Fix intermittent order based failure in UpdateStatusService spec (#30008) 2024-04-22 08:30:38 +00:00
support Update dependency selenium-webdriver to v4.19.0 (#29776) 2024-04-02 08:53:44 +00:00
system Move OAuth flow tests from feature tests to system tests (#29837) 2024-04-05 16:52:05 +00:00
validators Fix RSpec/DescribedClass cop (#29472) 2024-03-13 15:42:39 +00:00
views Pull out repeated setup to shared setup in statusus/show view spec (#29927) 2024-04-15 15:24:31 +00:00
workers Automatically switch from open to approved registrations in absence of moderators (#29318) 2024-02-21 17:45:06 +00:00
rails_helper.rb Use before_all block to setup requests/cache_spec data (#29437) 2024-03-13 08:38:57 +00:00
spec_helper.rb Change registrations to be disabled by default for new servers (#29280) 2024-02-22 13:28:19 +00:00