All contributions

mastodon/mastodon

Mastodon

Software for self-hosted microblogging servers that connect into one global network. The backend runs on Ruby on Rails.

Language
Ruby
GitHub stars
50,702
Merged changes
1
Project site
joinmastodon.org

What we changed

The terms of service and privacy policy API no longer returns a 500 error when the text contains a percent sign, because the serializers replace only %{domain} instead of running the whole text through format.

What this work shows

  • API serializers in Ruby on Rails
  • Safe placeholder substitution in user text
  • RSpec tests
What was broken

A percent sign broke the terms API

The terms of service and privacy policy serializers ran the text through format() to fill in %{domain}. Any other % sign, such as in "100%", was read as a format specifier, and /api/v1/instance/terms_of_service and privacy_policy returned a 500 error.

How we fixed it

Only %{domain} is replaced

The serializers now replace %{domain} with the server's domain using gsub and leave the rest of the text alone. New RSpec specs check a text with "100%" and the filled-in domain for both documents.

#41343

Merged change 1

  1. #41343 Fix terms of service and privacy policy API failing on percent signs Merged 27 October 2026

What it taught us

Text written by an admin must not go into a formatting function as if it were a template, or every special character becomes an error. We substitute only the one placeholder meant to be filled and add a test with the text that used to break the API.

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.