---
title: "Mastodon: percent signs and a 500 error in a Rails API"
description: "A fix in Mastodon in Ruby on Rails: the terms of service and privacy policy API no longer returns a 500 error when the text has a percent sign, as in 100%."
url: "https://vulcode.com/en/opensource/contributions/mastodon"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

mastodon/mastodon

# Mastodon

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

[See the repository](https://github.com/mastodon/mastodon) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Ruby
- **GitHub stars**: 50,702
- **Merged changes**: 1
- **Project site**: [joinmastodon.org](https://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](https://github.com/mastodon/mastodon/pull/41343)

## Merged change 1

- [#41343 Fix terms of service and privacy policy API failing on percent signs Merged 27 October 2026](https://github.com/mastodon/mastodon/pull/41343)

## 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

- [**Node.js** JavaScript · 123,955 stars The JavaScript runtime built on V8 that runs servers, command line tools and front-end build pipelines. It ships a built-in node:sqlite module for working with SQLite databases.](https://vulcode.com/en/opensource/contributions/nodejs)

- [**Godot Engine** C++ · 120,623 stars An open source, multi-platform 2D and 3D game engine with its own editor, where game developers build scenes and interfaces.](https://vulcode.com/en/opensource/contributions/godot)

- [**Material UI** JavaScript · 99,391 stars A React component library that implements Google's Material Design: ready-made text fields, selects, buttons and other interface elements.](https://vulcode.com/en/opensource/contributions/material-ui)

- [**Zed** Rust · 95,562 stars A fast code editor in Rust from the creators of Atom and Tree-sitter, with live multiplayer editing.](https://vulcode.com/en/opensource/contributions/zed)

- [**uv** Rust · 92,647 stars An extremely fast Python package and project manager written in Rust. It creates projects, installs dependencies and manages virtual environments.](https://vulcode.com/en/opensource/contributions/uv)

- [**Grafana** TypeScript · 78,050 stars An open observability and data visualisation platform that shows metrics, logs and traces from Prometheus, Loki, Elasticsearch, PostgreSQL and many other sources on dashboards.](https://vulcode.com/en/opensource/contributions/grafana)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
