intertwingly

It’s just data

HTML5-style "Google Suggest"


Anne van Kesteren: Dev Opera just published an article I wrote a few weeks back on request from our new editor, Chris Mills: An HTML5-style "Google Suggest". Thanks to Maciej, Simon, and Johannes for contributing to and implementing the idea of using datalist to emulate Google Suggest.

May I suggest the following patch?

--- an-html5-style-google-suggest.original.py   2007-10-11 13:42:33.000000000 -0400
+++ an-html5-style-google-suggest.py    2007-10-11 13:43:02.000000000 -0400
@@ -24,6 +24,7 @@
     # If a query string was provided we need to provide an XML file with
     # options filtered using the user input
     import sys
+    from xml.sax.saxutils import escape
     print "Content-type: application/xml"
     print "Cache-control: no-cache"
     print ""
@@ -31,5 +32,5 @@
     sys.stdout.write('  <option>[searching for "%s"]</option>' % qs[2:])
     for name in open('suggest.txt').readlines():
         if name.lower().find(qs[2:].lower())!=-1:
-            sys.stdout.write('<option>%s</option>' % name)
+            sys.stdout.write('<option>%s</option>' % escape(name))
     sys.stdout.write('</select>')

What happens if the name isn’t utf-8?