Skip to content

Commit

Permalink
html_rewriter: fixed attribute 'srcset' rewriting (webrecorder#712)
Browse files Browse the repository at this point in the history
Co-authored-by: Yasar Kunduz <[email protected]>
  • Loading branch information
yasarkunduz and Yasar Kunduz authored Aug 1, 2022
1 parent 62633a4 commit 32e9020
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pywb/rewrite/html_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _rewrite_srcset(self, value, mod=''):
return ''

values = (url.strip() for url in re.split(self.SRCSET_REGEX, value) if url)
values = [self._rewrite_url(v.strip()) for v in values]
values = [self._rewrite_url(v.split(' ')[0].strip()) + (' ' + ' '.join(v.split(' ')[1:])).rstrip() for v in values if v]
return ', '.join(values)

def _rewrite_meta_refresh(self, meta_refresh):
Expand Down
4 changes: 4 additions & 0 deletions pywb/rewrite/test/test_html_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
>>> parse('<img srcset="//example.com/1x,1x 2w, //example1.com/foo 2x, http://example.com/bar,bar 4x">')
<img srcset="/web/20131226101010///example.com/1x,1x 2w, /web/20131226101010///example1.com/foo 2x, /web/20131226101010/http://example.com/bar,bar 4x">
# complex srcset attrib
>>> parse('<img srcset="http://test.com/yaşar-kunduz.jpg 320w, http://test.com/yaşar-konçalves-273x300.jpg 273w">')
<img srcset="/web/20131226101010/http://test.com/ya%C5%9Far-kunduz.jpg 320w, /web/20131226101010/http://test.com/ya%C5%9Far-konc%CC%A7alves-273x300.jpg 273w">
# empty srcset attrib
>>> parse('<img srcset="">')
<img srcset="">
Expand Down

0 comments on commit 32e9020

Please sign in to comment.