From: Maxime Devos <maximedevos@telenet.be>
To: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
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: Sun, 21 Aug 2022 12:16:54 +0200 [thread overview]
Message-ID: <f604d73d-0ed1-68f9-d86b-9bf2d038b3e1@telenet.be> (raw)
In-Reply-To: <CA+XASoVEzySx3m15KAoDprEYu36Q0k6Cu=TsZhJM9XVMaBTn2g@mail.gmail.com>
[-- Attachment #1.1.1.1: Type: text/plain, Size: 2362 bytes --]
On 21-08-2022 02:05, Aleix Conchillo Flaqué wrote:
> 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
I am proposing to use XHTML (which is XML), not HTML. HTML's special
parsing quirks are irrelevant here.
> It does, browsers (at least Chrome) don't interpret that correctly,
> since it's not valid JavaScript.
As <script> ... </script> is XML, the XML parser (not the HTML parser,
this is XHTML!) will decode the < inside the <script>...</script>,
the result _after decoding_ is valid JavaScript. In XML, <script> is
not special -- everything is parsed the same way in XML.
Anyway, it seems to work for me, both in icecat and ungoogled-chromium:
> (use-modules (web server))
> (define document
> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
> <html xmlns=\"http://www.w3.org/1999/xhtml\">
> <head>
> <title>Test</title>
> </head>
> <body>
> <script type=\"text/javascript\">
> console.log(\"<Hi!>\");
> </script>
> </body>
> </html>")
>
> (define (handler request request-body)
> (values '((content-type application/xhtml+xml))
> document))
>
> (run-server handler 'http)
-- on the console, <Hi!> is logged, not <Hi!>.
If I replace < by < and > by > to make it 'valid JavasScript' as
you appear to be proposing, I get a parsing error:
>
> (ungoogled-chromium)
> This page contains the following errors:
>
> error on line 8 at column 17: error parsing attribute name
>
>
> Below is a rendering of the page up to the first error.
>
>
and
> (icecat):
> XML Parsing Error: not well-formed
> Location: http://localhost:8080/
> Line Number 8, Column 17:
> console.log("<Hi!>");
> ----------------^
Greetings,
Maxime.
[-- Attachment #1.1.1.2: Type: text/html, Size: 3859 bytes --]
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2022-08-21 10:16 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é
2022-08-21 5:09 ` tomas
2022-08-21 10:16 ` Maxime Devos [this message]
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=f604d73d-0ed1-68f9-d86b-9bf2d038b3e1@telenet.be \
--to=maximedevos@telenet.be \
--cc=aconchillo@gmail.com \
--cc=guile-devel@gnu.org \
--cc=guile-user@gnu.org \
/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).