Mention open_in_browser in the release notes

This commit is contained in:
Adrián Chaves 2023-11-29 12:13:04 +01:00
parent c947f51077
commit eb8b2c5197
3 changed files with 26 additions and 25 deletions

View File

@ -10,10 +10,10 @@ Scrapy 2.11.1 (unreleased)
**Security bug fix:**
- The regular expressions of the ``iternodes`` node iterator of
:class:`~scrapy.spiders.XMLFeedSpider` are no longer susceptible to a
`ReDoS attack`_. Please, see the `cc65-xxvf-f7r9 security
advisory`_ for more information.
- Fixed regular expressions susceptible to a `ReDoS attack`_ affecting the
``iternodes`` node iterator of :class:`~scrapy.spiders.XMLFeedSpider` and
the :func:`~scrapy.utils.response.open_in_browser` function. Please, see
the `cc65-xxvf-f7r9 security advisory`_ for more information.
.. _ReDoS attack: https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
.. _cc65-xxvf-f7r9 security advisory: https://github.com/scrapy/scrapy/security/advisories/GHSA-cc65-xxvf-f7r9
@ -2892,10 +2892,10 @@ Scrapy 1.8.4 (unreleased)
**Security bug fix:**
- The regular expressions of the ``iternodes`` node iterator of
:class:`~scrapy.spiders.XMLFeedSpider` are no longer susceptible to a
`ReDoS attack`_. Please, see the `cc65-xxvf-f7r9 security
advisory`_ for more information.
- Fixed regular expressions susceptible to a `ReDoS attack`_ affecting the
``iternodes`` node iterator of :class:`~scrapy.spiders.XMLFeedSpider` and
the :func:`~scrapy.utils.response.open_in_browser` function. Please, see
the `cc65-xxvf-f7r9 security advisory`_ for more information.
.. _release-1.8.3:

View File

@ -125,25 +125,15 @@ Fortunately, the :command:`shell` is your bread and butter in this case (see
See also: :ref:`topics-shell-inspect-response`.
Open in browser
===============
Sometimes you just want to see how a certain response looks in a browser, you
can use the ``open_in_browser`` function for that. Here is an example of how
you would use it:
can use the :func:`~scrapy.utils.response.open_in_browser` function for that:
.. code-block:: python
.. autofunction:: scrapy.utils.response.open_in_browser
from scrapy.utils.response import open_in_browser
def parse_details(self, response):
if "item name" not in response.body:
open_in_browser(response)
``open_in_browser`` will open a browser with the response received by Scrapy at
that point, adjusting the `base tag`_ so that images and styles are displayed
properly.
Logging
=======
@ -163,8 +153,6 @@ available in all future runs should they be necessary again:
For more information, check the :ref:`topics-logging` section.
.. _base tag: https://www.w3schools.com/tags/tag_base.asp
.. _debug-vscode:
Visual Studio Code

View File

@ -81,8 +81,21 @@ def open_in_browser(
],
_openfunc: Callable[[str], Any] = webbrowser.open,
) -> Any:
"""Open the given response in a local web browser, populating the <base>
tag for external links to work
"""Open *response* in a local web browser, adjusting the `base tag`_ for
external links to work, e.g. so that images and styles are displayed.
.. _base tag: https://www.w3schools.com/tags/tag_base.asp
For example:
.. code-block:: python
from scrapy.utils.response import open_in_browser
def parse_details(self, response):
if "item name" not in response.body:
open_in_browser(response)
"""
from scrapy.http import HtmlResponse, TextResponse