Curly quotes and dashes break code: how to straighten them
Curly quotes, curly apostrophes, en and em dashes and non-breaking spaces look like their plain versions, but a computer treats them as different characters. Code, CSV files, spreadsheet formulas and command lines expect the plain ones. A pasted quote stops being a string, a double hyphen in a flag turns into a dash, and a non-breaking space can stop a program reading a line. Straighten the characters before you paste into code, then test the result where it will run.
Fix pasted textPasted text has broken linesOpenWhere the characters come from
Word processors and many email programs replace straight quotes with curly ones as you type. This is called smart quotes. Word can also turn two hyphens into a dash. Web pages and some editors insert non-breaking spaces, U+00A0, which keep two words on one line. These characters are correct for typography, which is why they appear. They are wrong for anything a program reads.
What breaks, and where
| Where | What goes wrong |
|---|---|
| Source code | Curly quotes are not string delimiters, and many languages reject a curly quote or a non-breaking space outside a string |
| Shell commands | A dash typed as an en dash is not the option marker, so the program sees an unknown argument |
| CSV files | Parsers wrap fields in straight double quotes, so curly quotes do not protect a comma inside a field |
| Spreadsheet formulas | The curly quotes become part of the text, or the formula reports an error |
| JSON | Curly quotes are not valid string delimiters, so the parser fails |
Straighten them in fixmint
Three tools cover the usual cases, and each handles a different set of characters.
- Curly quotes. Open fix pasted text and tick Straighten curly quotes. It turns curly single quotes and apostrophes into a straight single quote, and curly double quotes into straight double quotes. It leaves dashes alone. Its other options, such as trimming lines and collapsing repeated spaces, are ticked by default.
- Dashes, ellipses and odd spaces. Open remove hidden characters and tick Also convert curly quotes, en/em dashes and … to plain ASCII. Dashes become a hyphen and the ellipsis becomes three dots. Non-breaking spaces become normal spaces by default. The marked view shows where each change was made.
- One character or phrase. Open find and replace, leave Regex off, and type the character in Find and its plain version in Replace. With Regex off, the Find box is literal, so a curly quote matches only itself.
Here is the second tool applied to a typical paste:
| Before | After |
|---|---|
| “Hello,” she said. | "Hello," she said. |
| It’s done. | It's done. |
| —verbose | -verbose |
The last row shows a limit. Each dash becomes one hyphen, so a double hyphen that a word processor merged into one em dash comes back as a single hyphen. Fix flags such as --verbose by hand after the conversion.
Paste the result where it will run and test it there. Straightening does not change the meaning of the text, so a successful run is the real check.
Check the result
Run the straightened text through remove hidden characters once more and read the marked view. Any mark left behind is a character the first pass did not cover, such as a zero-width space or an unusual space. The marked view shows where each one sits, so you can fix it in place.
The characters look almost identical on screen, so a visual check misses them. A straight quote and a curly one differ only slightly in shape, and an en dash looks like a hyphen in many fonts. Test the text, not your eyes.
When not to straighten
Keep curly quotes and dashes in text that people read in print or on a web page. They are the right typography there. Straighten only the copy that goes into code, a CSV, a formula or a command. For text you write in a word processor, switch off the smart-quote option if you will paste it into code later.
Edge cases
- Mixed quotes. A document can mix curly and straight quotes. Run the straightening step once, then search the result for any that remain, because sources differ.
- Apostrophes in words. A curly apostrophe in a contraction becomes a straight one, which is what most code expects. Check any contractions that appear inside a string.
- Keep the source. Straightening is one-way: a straight quote cannot tell you which curly quote it came from. Keep the original document, and make the change on a copy.
- Dashes in sentences. An em dash used as a break in a sentence becomes a hyphen, so "wait — stop" becomes "wait - stop". Retype it by hand if the text is for reading rather than code.
- Invisible characters. Pasted text can also contain zero-width spaces. They are not quotes, but they break code in a similar way. The hidden characters guide covers them.
