Skip to content
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

Improve open_in_browser base tag injection (#5319) #5320

Merged
merged 2 commits into from
Dec 21, 2021
Merged

Improve open_in_browser base tag injection (#5319) #5320

merged 2 commits into from
Dec 21, 2021

Conversation

zessx
Copy link
Contributor

@zessx zessx commented Nov 15, 2021

Fixes #5319

What changed

Use of re.sub instead of replace to inject <base> tag.

Copy link
Member

@Gallaecio Gallaecio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for the fix and the other 2 scenarios I mention under my suggestion?

scrapy/utils/response.py Outdated Show resolved Hide resolved
scrapy/utils/response.py Outdated Show resolved Hide resolved
scrapy/utils/response.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 15, 2021

Codecov Report

Merging #5320 (75ed765) into master (28eba61) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #5320   +/-   ##
=======================================
  Coverage   88.59%   88.59%           
=======================================
  Files         163      163           
  Lines       10616    10618    +2     
  Branches     1558     1558           
=======================================
+ Hits         9405     9407    +2     
  Misses        936      936           
  Partials      275      275           
Impacted Files Coverage Δ
scrapy/utils/response.py 89.79% <100.00%> (+0.43%) ⬆️

@zessx
Copy link
Contributor Author

zessx commented Nov 15, 2021

@Gallaecio I've added your suggestions (fix and format) to the original commit, and a additional commit for test coverage.

Note:
Opinionated change, instead of parsing HTML to detect <head> in HTML comments, I simply remove these comments, as they are not relevant. A test cover the IE conditional comment case.

@zessx zessx requested a review from Gallaecio November 15, 2021 13:54
Copy link
Member

@Gallaecio Gallaecio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

scrapy/utils/response.py Show resolved Hide resolved
@zessx
Copy link
Contributor Author

zessx commented Nov 15, 2021

Fixing flake8 failed check with python 3.10, related to the raw bytes regex.

@wRAR wRAR merged commit 9ec60e8 into scrapy:master Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open in Browser <base> replacement will fail if <head> has attributes
3 participants