1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

rewriting: try more granular modifers to distinguish embeds: (in part for ukwa/ukwa-pywb#6)

- 'ba_' - for <base> rewriting
- 'je_' - 'javascript-embed' default for client-side rewriting in wombat

better modifiers for css rewriting (server and client):
- 'ce_' - 'css-embed' for any url() embeds in CSS
- 'cs_' - for css stylesheet @import rewriting/other .css
This commit is contained in:
Ilya Kreymer 2018-02-10 09:17:15 -08:00 committed by John Berlin
parent b38cfb8d67
commit 5b7ca18e0f
No known key found for this signature in database
GPG Key ID: 6EF5E4B442011B02
3 changed files with 25 additions and 25 deletions

View File

@ -56,7 +56,7 @@ class HTMLRewriterMixin(StreamingRewriter):
'archive': 'oe_'},
'area': {'href': defmod},
'audio': {'src': 'oe_'},
'base': {'href': defmod},
'base': {'href': 'ba_'},
'blockquote': {'cite': defmod},
'body': {'background': 'im_'},
'button': {'formaction': defmod},

View File

@ -25,23 +25,23 @@ r"""
# Base Tests -- w/ rewrite (default)
>>> parse('<html><head><base href="http://example.com/diff/path/file.html"/>')
<html><head><base href="/web/20131226101010/http://example.com/diff/path/file.html"/>
<html><head><base href="/web/20131226101010ba_/http://example.com/diff/path/file.html"/>
# Full Path
>>> parse('<html><head><base href="http://example.com/diff/path/file.html"/>', urlrewriter=full_path_urlrewriter)
<html><head><base href="http://localhost:80/web/20131226101010/http://example.com/diff/path/file.html"/>
<html><head><base href="http://localhost:80/web/20131226101010ba_/http://example.com/diff/path/file.html"/>
# Full Path Scheme Rel Base
>>> parse('<base href="//example.com"/><img src="/foo.gif"/>', urlrewriter=full_path_urlrewriter)
<base href="//localhost:80/web/20131226101010///example.com/"/><img src="/web/20131226101010im_/http://example.com/foo.gif"/>
<base href="//localhost:80/web/20131226101010ba_///example.com/"/><img src="/web/20131226101010im_/http://example.com/foo.gif"/>
# Rel Base
>>> parse('<html><head><base href="/other/file.html"/>', urlrewriter=full_path_urlrewriter)
<html><head><base href="/web/20131226101010/http://example.com/other/file.html"/>
<html><head><base href="/web/20131226101010ba_/http://example.com/other/file.html"/>
# Rel Base + example
>>> parse('<html><head><base href="/other/file.html"/><a href="/path.html">', urlrewriter=full_path_urlrewriter)
<html><head><base href="/web/20131226101010/http://example.com/other/file.html"/><a href="/web/20131226101010/http://example.com/path.html">
<html><head><base href="/web/20131226101010ba_/http://example.com/other/file.html"/><a href="/web/20131226101010/http://example.com/path.html">
# Rel Base
>>> parse('<base href="./static/"/><img src="image.gif"/>', urlrewriter=full_path_urlrewriter)
@ -53,7 +53,7 @@ r"""
# ensure trailing slash added
>>> parse('<base href="http://example.com"/>')
<base href="/web/20131226101010/http://example.com/"/>
<base href="/web/20131226101010ba_/http://example.com/"/>
# Base Tests -- no rewrite
>>> parse('<html><head><base href="http://example.com/diff/path/file.html"/>', urlrewriter=no_base_canon_rewriter)
@ -244,29 +244,29 @@ r"""
<div style="background: url('abc.html')" onblah on-click="location = 'redirect.html'"></div>
>>> parse('<div style="background: url(\'/other_path/abc.html\')" onblah onclick="window.location = \'redirect.html\'"></div>')
<div style="background: url('/web/20131226101010/http://example.com/other_path/abc.html')" onblah onclick="window.WB_wombat_location = 'redirect.html'"></div>
<div style="background: url('/web/20131226101010ce_/http://example.com/other_path/abc.html')" onblah onclick="window.WB_wombat_location = 'redirect.html'"></div>
>>> parse('<i style="background-image: url(http://foo-.bar_.example.com/)"></i>')
<i style="background-image: url(/web/20131226101010/http://foo-.bar_.example.com/)"></i>
<i style="background-image: url(/web/20131226101010ce_/http://foo-.bar_.example.com/)"></i>
>>> parse('<i style=\'background-image: url("http://foo.example.com/")\'></i>')
<i style="background-image: url(&quot;/web/20131226101010/http://foo.example.com/&quot;)"></i>
<i style="background-image: url(&quot;/web/20131226101010ce_/http://foo.example.com/&quot;)"></i>
>>> parse('<i style=\'background-image: url(&quot;http://foo.example.com/&quot;)\'></i>')
<i style="background-image: url(&quot;/web/20131226101010/http://foo.example.com/&quot;)"></i>
<i style="background-image: url(&quot;/web/20131226101010ce_/http://foo.example.com/&quot;)"></i>
>>> parse('<i style=\'background-image: url(&#x27;http://foo.example.com/&#x27;)\'></i>')
<i style="background-image: url('/web/20131226101010/http://foo.example.com/')"></i>
>>> parse("<i style='background-image: url(&apos;http://foo.example.com/&apos;)'></i>")
<i style="background-image: url(&apos;/web/20131226101010/http://foo.example.com/&apos;)"></i>
<i style="background-image: url(&apos;/web/20131226101010ce_/http://foo.example.com/&apos;)"></i>
#>>> parse('<i style=\'background-image: url(&quot;http://исп/&quot;)\'></i>')
<i style="background-image: url(&quot;/web/20131226101010/http://%D0%B8%D1%81%D0%BF/&quot;)"></i>
# Style
>>> parse('<style>@import "/styles.css" .a { font-face: url(\'../myfont.ttf\') }</style>')
<style>@import "/web/20131226101010/http://example.com/styles.css" .a { font-face: url('/web/20131226101010/http://example.com/some/myfont.ttf') }</style>
<style>@import "/web/20131226101010cs_/http://example.com/styles.css" .a { font-face: url('/web/20131226101010ce_/http://example.com/some/myfont.ttf') }</style>
# Unterminated style tag, handle and auto-terminate
>>> parse('<style>@import url(styles.css)')

View File

@ -251,28 +251,28 @@ r"""
#=================================================================
>>> _test_css("background: url('/some/path.html')")
"background: url('/web/20131010/http://example.com/some/path.html')"
"background: url('/web/20131010ce_/http://example.com/some/path.html')"
>>> _test_css("background: url('../path.html')")
"background: url('/web/20131010/http://example.com/path.html')"
"background: url('/web/20131010ce_/http://example.com/path.html')"
>>> _test_css("background: url(\"http://domain.com/path.html\")")
'background: url("/web/20131010/http://domain.com/path.html")'
'background: url("/web/20131010ce_/http://domain.com/path.html")'
>>> _test_css('background: url(" http://domain.com/path.html ")')
'background: url(" /web/20131010/http://domain.com/path.html ")'
'background: url(" /web/20131010ce_/http://domain.com/path.html ")'
>>> _test_css('background: url(" http://domain.com/path.html x ")')
'background: url(" /web/20131010/http://domain.com/path.html x ")'
'background: url(" /web/20131010ce_/http://domain.com/path.html x ")'
>>> _test_css("background: url(file.jpeg)")
'background: url(file.jpeg)'
>>> _test_css("background:#abc url('/static/styles/../images/layout/logo.png')")
"background:#abc url('/web/20131010/http://example.com/static/images/layout/logo.png')"
"background:#abc url('/web/20131010ce_/http://example.com/static/images/layout/logo.png')"
>>> _test_css("background:#000 url('/static/styles/../../images/layout/logo.png')")
"background:#000 url('/web/20131010/http://example.com/images/layout/logo.png')"
"background:#000 url('/web/20131010ce_/http://example.com/images/layout/logo.png')"
>>> _test_css("background: url('')")
"background: url('')"
@ -281,7 +281,7 @@ r"""
'background: url ("weirdpath\')'
>>> _test_css("@import url ('/path.css')")
"@import url ('/web/20131010/http://example.com/path.css')"
"@import url ('/web/20131010cs_/http://example.com/path.css')"
>>> _test_css("@import url('path.css')")
"@import url('path.css')"
@ -290,19 +290,19 @@ r"""
"@import ( 'path.css')"
>>> _test_css("@import \"/path.css\"")
'@import "/web/20131010/http://example.com/path.css"'
'@import "/web/20131010cs_/http://example.com/path.css"'
>>> _test_css("@import ('../path.css\"")
'@import (\'/web/20131010/http://example.com/path.css"'
'@import (\'/web/20131010cs_/http://example.com/path.css"'
>>> _test_css("@import ('../url.css\"")
'@import (\'/web/20131010/http://example.com/url.css"'
'@import (\'/web/20131010cs_/http://example.com/url.css"'
>>> _test_css("@import (\"url.css\")")
'@import ("url.css")'
>>> _test_css("@import url(/url.css)\n@import url(/anotherurl.css)\n @import url(/and_a_third.css)")
'@import url(/web/20131010/http://example.com/url.css)\n@import url(/web/20131010/http://example.com/anotherurl.css)\n @import url(/web/20131010/http://example.com/and_a_third.css)'
'@import url(/web/20131010cs_/http://example.com/url.css)\n@import url(/web/20131010cs_/http://example.com/anotherurl.css)\n @import url(/web/20131010cs_/http://example.com/and_a_third.css)'
"""