New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <script> and <style> text content serialization #218

Merged
merged 1 commit into from Dec 23, 2016

Conversation

Projects
None yet
2 participants
@plq
Contributor

plq commented Dec 21, 2016

Behold:

>>> from six import BytesIO
>>> from lxml import etree
>>> f = BytesIO()
>>> with etree.htmlfile(f) as xf:
...     elt = etree.Element('script')
...     elt.text = "if (a < b);"
...     xf.write(elt)
...
>>> f.getvalue()
'<script>if (a < b);</script>'

... which is correct.

However:

>>> f = BytesIO()
>>> with etree.htmlfile(f) as xf:
...     with xf.element('script'):
...         xf.write("if (a < b);")
...
>>> f.getvalue()
'<script>if (a &lt; b);</script>'

... which is not only incorrect, but also quite annoying :)

This patch is an attempt at fixing it.

Show outdated Hide outdated src/lxml/serializer.pxi Outdated

@scoder scoder merged commit bc77035 into lxml:master Dec 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment