{"id":19033,"date":"2009-02-25T10:00:00","date_gmt":"2009-02-25T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/02\/25\/smart-quotes-the-hidden-scourge-of-text-meant-for-computer-consumption\/"},"modified":"2023-12-24T09:26:54","modified_gmt":"2023-12-24T17:26:54","slug":"20090225-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090225-00\/?p=19033","title":{"rendered":"Smart quotes: The hidden scourge of text meant for computer consumption"},"content":{"rendered":"<p>Smart quotes\u2014you know, those fancy quotation marks that curl \u201clike this\u201d \u2018and this\u2019 instead of standing up straight &#x22;like this&#x22; &#x27;and this&#x27;\u2014are great for text meant for humans to read. Like serifs and other typographic details, they act as subtle cues that aid in reading.<\/p>\n<p>But don&#8217;t let a compiler or interpreter see them.<\/p>\n<p>In most programming languages, quotation marks have very specific meanings. They might be used to enclose the text of a string, they might be used to introduce a comment, they might even be a scope resolution operator. But in all cases, the language specification indicates that the role is played by the quotation mark U+0022 or apostrophe U+0027. From the language&#8217;s point of view, the visually similar characters U+2018, U+2019, and U+02BC (among others) are completely unrelated.<\/p>\n<p>I see this often on Web sites, where somebody decided to &#8220;edit&#8221; the content to make it &#8220;look better&#8221; by curlifying the quotation marks, turning what used to be working code into a big pile of syntax errors.<\/p>\n<p>I even see it in email. Somebody encounters a crash in a component under development and connects a debugger and sends mail to the component team describing the problem and including the information on how to connect to the debugger like this:<\/p>\n<blockquote class=\"m\"><p>WinDbg \u2013remote npipe:server=abc,pipe=def<\/p><\/blockquote>\n<p>Or maybe like this:<\/p>\n<blockquote class=\"m\"><p><a href=\"http:\/\/technet2.microsoft.com\/windowsserver\/en\/library\/0926da81-f03a-4986-959d-827b6753c22f1033.mspx\"> Remote.exe<\/a> \u201cabc\u201d \u201cdef\u201d<\/p><\/blockquote>\n<p>And you, as a member of the team responsible for that component copy the text out of the email (to ensure there are no transcription errors) and paste it into a command line.<\/p>\n<pre>C:\\&gt; Remote.exe \"abc\" \"def\"\r\n<\/pre>\n<p>and you get the error<\/p>\n<pre>Unable to connect to server \u00f4abc\u00f6\r\n<\/pre>\n<p>What happened? You got screwed over by smart quotes. The person who sent the email had smart quotes turned on in their email editor, and it turned &#8220;abc&#8221; into \u201cabc\u201d. You then got lulled into a false sense of security by <a href=\"http:\/\/blogs.msdn.com\/michkap\/archive\/2005\/02\/13\/371895.aspx\"> the best fit behavior of <code>WideCharToMultiByte<\/code><\/a>, which says <i>I can&#8217;t represent \u201c and \u201d in the console code page, but I can map them to &#8221; which is a close visual approximation, so I&#8217;ll use that instead<\/i>. As a result, the value you see on the command line shows straight quotes, but that&#8217;s just a fa\u00e7ade behind which the ugly smart quotes are lurking.<\/p>\n<p>I&#8217;ve even seen people hoist by their own smartly-quoted petard.<\/p>\n<blockquote class=\"q\">\n<p>I can&#8217;t seem to access a file called <code>aaa bbb.txt<\/code>. The command<\/p>\n<p>type \u201caaa bbb.txt\u201d<\/p>\n<p>results in the strange error message<\/p>\n<p>The system cannot find the file specified.<br \/>\nError occurred while processing: &#8220;a.<br \/>\nThe system cannot find the file specified.<br \/>\nError occurred while processing: x.txt&#8221;.<\/p>\n<p>Why can&#8217;t I access this file?<\/p>\n<\/blockquote>\n<p>Somehow they managed to type smart quotes <i>into their own command line<\/i>.<\/p>\n<p>So watch out for those smart quotes. When you&#8217;re sending email containing code or command lines, make sure your editor didn&#8217;t &#8220;make it pretty&#8221; and in the process destroy it.<\/p>\n<p><b>Exercise<\/b>: What is wrong with the WinDbg command line above?<\/p>\n<p><b>Bonus chatter<\/b>: <a href=\"http:\/\/www.leeholmes.com\/blog\/\"> PowerShell<\/a> is a notable exception to this principle, for it <a href=\"http:\/\/windowsitpro.com\/article\/articleid\/97740\/powershell-got-smart-about-smart-quotes.html\"> treats all flavors of smart quotes and smart dashes as if they were dumb quotes and dumb dashes<\/a>. From what I can tell, <a href=\"http:\/\/www.vistax64.com\/powershell\/13694-smart-quote-behavior-current-behavior-ideal.html\"> you have this guy to thank<\/a> (or blame).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>They look pretty but act differently.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-19033","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>They look pretty but act differently.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=19033"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19033\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=19033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=19033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=19033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}