Re: [guile-lib] html->sxml does not decode entities in attributes

"Dr. Arne Babenhauserheide" <[email protected]> Wed, 05 Feb 2025 12:34:33 +0100
Newsgroups gmane.lisp.guile.devel
Message-ID <[email protected]>
Tomas Volf <[email protected]> writes:
> I think I found a bug in the htmlprag module in guile-lib.  When parsing
> attributes, the values are not properly decoded:

Thank you for the report!

> --8<---------------cut here---------------start------------->8---
> scheme@(guile-user)> ,use (htmlprag)
> scheme@(guile-user)> (html->sxml "<hr aaa=\"bbb&quot;ccc'ddd\" />")
> $1 = (*TOP* (hr (@ (aaa "bbb&quot;ccc'ddd"))))
> scheme@(guile-user)> (html->sxml "<a href=\"a&amp;b\" />")
> $2 = (*TOP* (a (@ (href "a&amp;b"))))
> --8<---------------cut here---------------end--------------->8---
>
> I think that $1 should be "bbb\"ccc'ddd" and $2 should be "a&b".

The other way round does encode, so the round-trip is broken and this
definitely is a bug:

> ,use (htmlprag)
> (html->sxml "<hr aaa=\"bbb&quot;ccc'ddd\" />")
$1 = (*TOP* (hr (@ (aaa "bbb&quot;ccc'ddd"))))
> (sxml->html '(*TOP* (hr (@ (aaa "bbb&quot;ccc'ddd")))))
$2 = "<hr aaa=\"bbb&quot;ccc'ddd\" />"
> (sxml->html '(*TOP* (hr (@ (aaa "bbb\"ccc'ddd")))))
$3 = "<hr aaa=\"bbb&quot;ccc'ddd\" />"

> (html->sxml (sxml->html '(*TOP* (hr (@ (aaa "bbb\"ccc'ddd"))))))
$4 = (*TOP* (hr (@ (aaa "bbb&quot;ccc'ddd"))))

> I see few ways forward:
>
> 1. Document the current behavior and keep it as it is.
> 2. Add argument #:decode-attributes, defaulting to #f, to the relevant
>    procedures, so that people can opt into the fixed behavior.
> 3. Introduce parameter %decode-attributes, so that people can opt into
>    the fixed behavior.
>
> I am sure there are also other approaches possible.

Since htmlprag already uses parameters for customization
(%strict-tokenizer?), option 3 sounds best to me.

http://git.savannah.nongnu.org/gitweb/?p=guile-lib.git;a=blob;f=src/htmlprag.scm;h=79a7b2f33b0755474bfc015912c01bdf6c676a15;hb=HEAD#l44

(but I’m not the maintainer, so others may have a different opinion)

Can you create a patch?

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de
signature.asc (application/pgp-signature, 1.1 KB)
-----BEGIN PGP SIGNATURE-----

iQJEBAEBCAAuFiEE801qEjXQSQPNItXAE++NRSQDw+sFAmejTMkQHGFybmVfYmFi
QHdlYi5kZQAKCRAT741FJAPD64B/D/4rWPknPVzjfzJU07VduB0EeDve2sA2eteh
iudmdcvThlTBMuoFnVTgIF8iiauygliL4HaptV4mXW5qvJkw1cD8SsRrwOjWKwIv
Mdmtz73RkDg4uHLT9LbrdwIkPeXwGfhJYK21DmuVFJTzDAJ5QgC3BKREvUtzwCkL
0cDhdo7YQby9jZpVMSnyt4JyqqRcp6wosVcD4Pb53Q05A1up/bve+X7TDigcB9P4
Wv8Q00gRNU3AC22xvUaNfEjR4DxxmPi2wm0/twEuWVOl6IHc3DTbfNx5/ZztNuwp
QLyABVY5rw53Ndb4CNMvRfeuEyzpsJ6EGzx9UminQBJA/yECN774jVOX2bJlfvX8
kUdqPkXOsdxitp0UQuSIgar37dpzBNe+MslaHyVKCSWDluxCd+bc/UFGcoLDeq6s
zUlvQgt2Owr7MRl9cGsgx2gOUY05/n9pvl28NIJuZybwMI6u/ts5BGRpXIVMHL5Y
2Zk1pExPJ7O3X/C6Pb1iNgEwhLs7By0fBNfCa5JBFIzM63S4/WTCrPI5IhTqP5Mv
/EqarID/5CJQu6zEwjzuqMplodAGBve2LovwHVHcWsfmwMNWifVGsE8MPmVMP/on
DIAYj9YME9/zoUl7bLRrNP5LAGOBHfemr7OsR2BwQFWwrO7VwLDxEiEoTLRas6YH
9RMQ3jl23ojEBAEBCAAuFiEE3Si95tmHXKvOSosd3M8NswvBBUgFAmejTMkQHGFy
bmVfYmFiQHdlYi5kZQAKCRDczw2zC8EFSI5oA/0de76d6eXskTrPDeg+Ao3Def2F
cxs9TyCvKHKcyaHynLjbfNJFoR9B4FdaYQSBQf6ghfTuXQf3QVC8JcJbYA9n/vqU
UdJAgtkikJx/WZfUpg9xcISV6n4swPTZPLITX5gcL08K66MGhm2CRDqPKom6huTk
H4aOokofe6jVM3nqPw==
=Jgve
-----END PGP SIGNATURE-----