I'm sure CGI or something has a bulit in helper that does this. There are probably some edge-cases here, i.e., shouldn't the key be escaped as well?