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
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 edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.