Skip to content

Commit

Permalink
Updated RewriteInfo._resolve_text_type to recognize the fr_ rewrite…
Browse files Browse the repository at this point in the history
… modifier (indicates that the content is from a frameset's frame) (#438)

Added a test, test_rewrite_frameset_frame_content, to test_content_rewriter.py for these changes
  • Loading branch information
N0taN3rd authored and ikreymer committed Feb 5, 2019
1 parent 529a587 commit 777cc30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pywb/rewrite/content_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _resolve_text_type(self, text_type):
# if html or no-content type, allow resolving on js, css,
# or other templates
if text_type in ('guess-text', 'guess-html'):
if not is_js_or_css and mod not in ('if_', 'mp_', 'bn_', ''):
if not is_js_or_css and mod not in ('fr_', 'if_', 'mp_', 'bn_', ''):
return None

# if application/octet-stream binary, only resolve if in js/css content
Expand Down
18 changes: 18 additions & 0 deletions pywb/rewrite/test/test_content_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,24 @@ def test_custom_fuzzy_replace(self):

assert b''.join(gen).decode('utf-8') == '{"ssid":"5678"}'

def test_rewrite_frameset_frame_content(self):
"""Determines if the content rewriter correctly determines that HTML loaded via a frameset's frame,
frame's src url is rewritten with the **fr_** rewrite modifier, is content to be rewritten
"""
headers = {'Content-Type': 'text/html; charset=UTF-8'}
prefix = 'http://localhost:8080/live/'
dt = '20190205180554%s'
content = '<!DOCTYPE html><head><link rel="icon" href="http://r-u-ins.tumblr.com/img/favicon/72.png" ' \
'type="image/x-icon"></head>'
rw_headers, gen, is_rw = self.rewrite_record(headers, content, ts=dt % 'fr_',
prefix=prefix,
url='http://r-u-ins.tumblr.com/',
is_live='1')
# is_rw should be true indicating the content was rewritten
assert is_rw
assert b''.join(gen).decode('utf-8') == content.replace('href="', 'href="%s%s' % (prefix, dt % 'oe_/'))
assert rw_headers.headers == [('Content-Type', 'text/html; charset=UTF-8')]

def test_custom_live_only(self):
headers = {'Content-Type': 'application/json'}
content = '{"foo":"bar", "dash": {"on": "true"}, "some": ["list"]'
Expand Down

0 comments on commit 777cc30

Please sign in to comment.