unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
To: Maxime Devos <maximedevos@telenet.be>
Cc: guile-user <guile-user@gnu.org>, guile-devel <guile-devel@gnu.org>
Subject: Re: avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html
Date: Sat, 20 Aug 2022 17:05:22 -0700	[thread overview]
Message-ID: <CA+XASoVEzySx3m15KAoDprEYu36Q0k6Cu=TsZhJM9XVMaBTn2g@mail.gmail.com> (raw)
In-Reply-To: <4425bd42-90fa-c083-717d-8b7def122e59@telenet.be>

Hi Maxime,

On Sat, Aug 20, 2022 at 2:48 PM Maxime Devos <maximedevos@telenet.be> wrote:
>
> The GuileScript looks nice, for interested readers, see <
https://github.com/aconchillo/guilescript>
>
> On 20-08-2022 21:59, Aleix Conchillo Flaqué wrote:
>
> However, I'm not able to find a way to avoid character encoding/escaping
and the generated code inside <script> will always have "&lt;", etc. And
<script> is a place where encodings can be avoided. This is true for both
Guile and guile-lib's (htmlprag), even though htmlprag's escapes less
characters (e.g. double quotes).
>
> One way I found to solve this was to have <script src="fib.js"> and then
have a handler for fib.js that would just return the transpiled string. But
it's not as nice, it's extra work and it's also an additional roundtrip to
the server.
>
> Has anyone ran into this issue? Would is make sense to add a keyword
argument to (sxml->xml)? For example, (sxml->xml SXML PORT #:escape #f).
>
> > Having unescaped < in <script>...</script> does not seem valid XML to
me.
>

According to the spec, embedding inline content in the <script> tag should
conform to the language defined by the "type" attribute (defaults to
javascript). So, I would expect you could put any string that conforms to
JS.

"""
When used to include dynamic scripts, the scripts may either be embedded
inline or may be imported from an external file using the src attribute. If
the language is not that described by "text/javascript", then the type
attribute must be present, as described below. Whatever language is used,
the contents of the script element must conform with the requirements of
that language's specification
"""

> Does escaping &lt; actually cause problems?  If so, you could look into
declaring your web page as XHTML, with an appropriate doctype and
Content-Type.
>
> I would expect XHTML to accept &lt; and reject unescaped <, being XML and
not the messy syntax of HTML, but it's not something I have tried out
myself.
>

It does, browsers (at least Chrome) don't interpret that correctly, since
it's not valid JavaScript.

In any case, I just went by using my work around of loading the JS as a
separate file:

https://github.com/aconchillo/guilescript/blob/master/examples/fibonacci-server.scm

Best,

Aleix


  reply	other threads:[~2022-08-21  0:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20 19:59 avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html Aleix Conchillo Flaqué
2022-08-20 21:48 ` Maxime Devos
2022-08-21  0:05   ` Aleix Conchillo Flaqué [this message]
2022-08-21  5:09     ` tomas
2022-08-21 10:16     ` Maxime Devos
2022-08-21 10:23       ` tomas
2022-08-21 22:34       ` Aleix Conchillo Flaqué

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+XASoVEzySx3m15KAoDprEYu36Q0k6Cu=TsZhJM9XVMaBTn2g@mail.gmail.com' \
    --to=aconchillo@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=maximedevos@telenet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).