While "Bush hid the facts" is the sentence most commonly presented to induce the error, the bug can be triggered by other strings, for example "hhhh hhh hhh hhhhh"[2] or "this app can break",[3] and even "a " or "z!".[1]
The bug occurs when the string is passed to the Win32 charset detection function IsTextUnicode. IsTextUnicode guesses it is Unicode if the "hi byte" (the odd indexes) changes three times less than the "low byte",[1] if so it
returns true, and the application then incorrectly interprets the text as UTF-16LE.[4]
The bug had existed since IsTextUnicode was introduced with Windows NT 3.5 in 1994, but was not discovered until early 2004.[5] Many text editors and tools exhibit this behavior on Windows because they use IsTextUnicode to determine the encoding of text files. As of Windows Vista, Notepad has been modified to use a different detection algorithm that does not exhibit the bug, but IsTextUnicode remains unchanged in the operating system, so any other tools that use the function are still affected.[6]
Add a character so the string is an odd number of bytes long.
Save the file as "UTF-8" (before 2018) or "UTF-8 with BOM" (after 2018) rather than "ANSI". This prepends a UTF-8 byte order mark which avoids the bug.[citation needed] UTF-8 without the byte order mark would still trigger the bug, as it is identical to the "ANSI" file.
Saving as "Unicode", which in Microsoft Windows means UTF-16LE. When loading this text IsTextUnicode should (and does) return true and the text is correct.
To retrieve the original text using Notepad, bring up the "Open a file" dialog box, select the file, select "ANSI" or "UTF-8" in the "Encoding" list box, and click Open. Under Windows 2000, Notepad lacks the "Encoding" list box. WordPad appears to load the text correctly without choosing the encoding, since it uses its own encoding detection.
^Kaplan, Michael S. (14 June 2006). "Behind 'How to break Windows Notepad'". archives.miloush.net. Archived from the original on 25 October 2013. Retrieved 2022-07-12.{{cite web}}: CS1 maint: bot: original URL status unknown (link)