The 140-Character Lie — JavaScript Bug Hunt
Inspired by Twitter's infamous character-counter quirks: links are supposed to cost a flat 23 characters (the t.co wrapper), and an emoji is one character…
- Language: JavaScript
- Layer: Frontend
- Difficulty: Easy
- Concepts: Strings, Unicode
- Modelled on: Twitter
- Visible tests: plain text counts its characters; a URL costs a flat 23; an emoji is one character
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- a URL costs a flat 23 — 6 text + 23 url + 4 text: expected 33 but got 49
- an emoji is one character — expected 2 but got 4
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by Twitter's infamous character-counter quirks: links are supposed to cost a flat 23 characters (the t.co wrapper), and an emoji is one character to a human — yet the composer keeps blocking tweets that should fit.
Fix charCount.js so the counter matches the spec.
Bug report
BUG-140 · Reported by: composer team
Spec: every URL counts as exactly 23 characters; everything else counts in user-perceived characters (code points), not UTF-16 units.
Observed:
- "check https://a.very/long/path…" is counted at the URL's full length
- a single 🙂 is counted as TWO characters
Logs
[composer] countTweet("🙂") -> 2 (expected 1)
[composer] over-limit block fired at 138 visible charsThe code as shipped
src/tweet/charCount.js (editable)
// Counts a tweet the way the platform bills it.
// Spec: URLs cost a flat 23 characters; text is counted in code points.
var URL_COST = 23;
exports.countTweet = function (text) {
return text.length;
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.