Unicode/UTF-8 confusion

Marc Christiansen usenet at solar-empire.de
Sat Mar 15 14:31:09 EDT 2008


Tom Stambaugh <tms at zeetix.com> wrote:
>> Somehow I don't get what you are after.  The ' doesn't have to be escaped
>> at all if " are used to delimit the string.  If ' are used as delimiters
>> then \' is a correct escaping.  What is the problem with that!?
> 
> If I delimit the string with double quote, then I have to escape every
> double quote in whatever I serialize. I'm moving strict html from the server
> to the browser, and therefore the value of every tag attribute is delimited
> by double quotes. That means that I'd have to escape every double quote, and
> there are MANY more of them.

I haven't done much programming with Javascript/AJAX, so why is the
following not sufficient? All the double quotes get escaped.

 >>> link = u"""<a href="asd" title="Peter's child">Click here</a>"""
 >>> simplejson.dumps(link)
 '"<a href=\\"asd\\" title=\\"Peter\'s child\\">Click here<\\/a>"'
 >>> print simplejson.dumps(link)
 "<a href=\"asd\" title=\"Peter's child\">Click here<\/a>"

And ' is a valid delimiter for attributes, so you don't have to use
double quotes for them.

Marc



More information about the Python-list mailing list