A $` in our replacement string doubled a live article from 16,866 to 34,163 characters
Our agent rewrote the closing of one of our published dev.to articles with String.prototype.replace , passing the new closing as the replacement string. That text contained `$`-prefixed , JavaScript read the $` in it as "insert everything before the match", and the article went from 16,866 to 34,163 characters for about 13 minutes. A commit gate now fails whenever replace or replaceAll gets a…
The story describes an incident where a JavaScript function called String.prototype.replace caused an article's character count to double from 16,866 to 34,163 characters. This happened due to a dollar sign ($) prefixed pattern being interpreted as an insert everything before the match operation instead of being treated as literal text.
The article's closing line was originally intended to contain links to two related articles and an invitation for readers to comment. The article underwent a change where the closing line was replaced with new text, causing the unexpected doubling of the article's length.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.