Why does pasting a string containing an illegal filename character into a rename edit box delete the characters from the clipboard, too?

Raymond Chen


Ane asks why, if you have a string with an illegal filename character on the clipboard, and you paste that string into a rename edit box, do the illegal characters get deleted not just from the edit box but also the clipboard? Basically, it’s a bug, the result of a poor choice of default in an internal helper class. There is an internal helper class for “monitoring an edit control” with options to do things like remove illegal characters. This helper class was written back in 1998, presumably with the intention of being used somewhere, but it never did get hooked up. Maybe the feature it was originally written for got cancelled, I can’t quite tell. At any rate, this helper class had many options, one of which was “When pasting text containing illegal characters, should I filter the illegal characters from the clipboard, too?”, and for some reason it defaulted to Yes. (I can see why the default was Yes from a coding standpoint. It was actually less work to filter the characters from the clipboard that it was to preserve them, but it’s a bad default from an API design standpoint.) Anyway, this helper class sat unused for a few years, but in 2000, Explorer decided to use this helper class so it could filter illegal characters out of file names when you used the Rename command. The code that uses this helper class chose which options it wanted, and probably due to oversight, the “preserve clipboard contents when pasting” flag was not specified.

So yeah, it’s just a bug. But then again, it’s a bug that’s been around for over a decade, so who knows if there’s somebody out there that relies on it.


Comments are closed. Login to edit/delete your existing comments