[plt-scheme] Raw HTML in web server output
When you make a full response [1], you give the web server a [byte] string
rather than an Xexpr. A substring of this string could be a user provided
string.
If you want to write your application with Xexprs and contain the user's
string in it, then make a new data structure and catch the error xml->string
throws, kind of like this:
(define-struct dave-gurnell-strings (the-user-string))
(make-response/full
....
(with-handlers ([exn:invalid-xexpr?
(lambda (exn)
(if (dave-gurnell-strings? (exn:invalid-xexpr-code
exn))
(dave-gurnell-strings-the-user-string
(exn:invalid-xexpr-code exn))
(raise exn)))])
(xml->string the-xexpr+dgstrings))
.....)
Jay
1.
http://download.plt-scheme.org/doc/301/html/web-server/web-server-Z-H-12.html#node_sec_10.1.3
On 3/21/06, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
>
> Dear Schemers,
>
> I'm trying to write a simple (!!) CMS-style page editor using web-
> server. I have a web form containing a textarea into which the user
> types some HTML. I want to take said HTML, store it in a database,
> and then write it out as part of a web page later on.
>
> I am using the htmlprag package for the convenience of its (write-
> shtml-as-html ...) procedure. I originally thought said procedure
> might allow me to output raw, unadulterated HTML as a string. This is
> not the case, however.
>
> I suppose I *could* use htmlprag to parse the user's input into
> XSHTML before it is stored in the database. However, I don't like the
> idea of a user typing something in, saving their page, and then
> coming back to edit it again and finding it changed because htmlprag
> has "corrected" mistakes in the structure. I would prefer the user to
> make mistakes and leave them in the page.
>
> Does anyone have any suggestions or recommendations?
>
> Many thanks,
>
> -- Dave
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
--
Jay McCarthy <jay at cs.brown.edu>
http://jay.makeoutcity.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060321/471b71a7/attachment.html>