« Little Tokyo Unplugged | It's Finally Over »

ASCII, Dammit!

posted 8 Jan 2008 (Tue) at 1:39p.m. from the office

I just discovered a little chunk of code that made me laugh out loud. Seriously, a coworker came over to ask what was going on and I had to explain it. In case you're wondering too, the chunk of code is called <a href="http://newsbruiser.tigris.org/source/browse/~checkout~/newsbruiser/nb/lib/AsciiDammit.py">AsciiDammit.py</a>.

One of the banes of a web programmer's existence is dealing with user input, which can come in almost any form. You have to allow for malicious hackers who try to crash your site using strangely-formatted text, sure, but you also have to allow for users who write text in Microsoft apps like <a href="http://www.gnu.org/philosophy/no-word-attachments.html">Word</a>, which can also crash your site.

Microsoft, for their own insidious reasons, uses non-standard codes to represent things like "smart quotes", short and long dashes, etc. These codes cause errors in other programs unless they are converted, so every web programmer who hasn't sold out to The Man has to scrub user input before doing anything else with it.

Bless Leonard Richardson! He wrote a little <a href="http://python.org">Python</a> class that handles this chore (and perfectly captures my feelings about this whole chore) called "AsciiDammit.py". I love it! The class also has a function called htmlDammit(), that works one HTML with "smart quotes" in it. Genius!

P.S. If you're interesting in alternatives to Word, there were a couple <a href="http://www.nytimes.com/2008/01/06/magazine/06wwln-medium-t.html?ex=1357275600&en=e0f04d9791fe6b3a&ei=5090&partner=rssuserland&emc=rss&pagewanted=all">good</a> <a href="http://stevenpoole.net/blog/goodbye-cruel-word/">articles</a> about cool alternatives the other day.

<strong>UPDATE (2008-2-6):</strong> I just figured out that the Leonard Richardson behind ASCII, Dammit! is the same Leonard Richardson who wrote <a href="http://www.amazon.com/exec/obidos/redirect?path=ASIN/0596529260&link_code=as2&camp=1789&tag=crummthesite-20&creative=9325">RESTful Web Services</a> and the most excellent HTML parsing lib <a href="http://crummy.com/software/BeautifulSoup/">BeautifulSoup</a>, <a href="http://crummy.com/">His site</a> is chock full 'o interesting stuff, like <a href="http://crummy.com/source/software/download/ThePowerOfGreypoint.py">a script</a> that turns a ReST-formatted text into presentation slides. I wanna be like Leonard when I grow up. :)

permalink

Add a comment