[plt-scheme] Escaping in X-expression attributes

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Aug 9 15:15:07 EDT 2002

jason songhurst wrote:
> Jens Axel Søgaard wrote:
>> I have a hard time figuring out how to get the web-
>> server to produce a " or a ' in the output when feeded
>> an X-expression. I simply can't figure out how to
>> escape properly in the attributes  of X-expressions.
>
> the code that escapes characters (converts ' into ')
> in attributes (and in xml text, but that isn't really
> your concern) is in the file: "collects/xml/private/writer.ss"
>
> see specifically the definition of (write-xml-element
> ...), which calls (escape s alist). the (escape ...)
> function is where the work is done.
>
> in summary:
>    as currenly (v201) written, there is no escape from
> the escape.  :)

I was afraid of that, I did look there but I thought,
there were some kind of alternative.

> but there are workarounds...  here are some that i found.
> you may find others.
>
> workaround 1:
>    remove the ''' escape from the escape-attribute-
> table    (line 153 in writer.ss)
>
>    it is not needed if the string is quoted with double
> quotes.    the only chars that need to be escaped in
> double-quoted attribute    values are &, <, and ".

I'll use this one for now.

> workaround 2: (if you can't change the library)
>    un-escape manually.
>
>    find the '&apos;' strings and replace them with single
> quotes.
>
>    for example:
>    (define remove-apos
>      (let ((re (regexp "&apos;")))
>        (lambda (s)
>          (regexp-replace* re s "'"))))

This doesn't work since it is the web-server that gets the
X-expression, and consequently the printing.

(Unless you meant to put the above in the web-server :-) )

--
Jens Axel Søgaard





Posted on the users mailing list.