Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: src/caterpillar.py

Issue 1644543005: inject_misc_tags no longer fails if document has no head. Resolves #16. (Closed) Base URL: git@github.com:chromium/caterpillar.git@master
Patch Set: Response to CR Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/caterpillar_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/caterpillar.py
diff --git a/src/caterpillar.py b/src/caterpillar.py
index 4a0a8b5c38e4e035c8b1953a6cd4babbfe734961..085ecf93c8a0ddde53b6a7e390d67a3aade80fd7 100755
--- a/src/caterpillar.py
+++ b/src/caterpillar.py
@@ -286,22 +286,30 @@ def inject_misc_tags(soup, ca_manifest, root_path, html_path):
This can be either absolute or relative.
html_path: Path to the HTML document being modified.
"""
+ head = soup.head
+ if not head:
+ head = soup.new_tag('head')
+ if soup.html:
+ soup.html.insert(0, head)
+ else:
+ soup.insert(0, head)
+
# Add manifest link tag.
manifest_path = os.path.join(root_path, PWA_MANIFEST_FILENAME)
manifest_link = soup.new_tag('link', rel='manifest', href=manifest_path)
- soup.head.append(manifest_link)
+ head.append(manifest_link)
# Add meta tags (if they don't already exist).
for tag in ('description', 'author', 'name'):
if tag in ca_manifest and not soup('meta', {'name': tag}):
meta = soup.new_tag('meta', content=ca_manifest[tag])
meta['name'] = tag
- soup.head.append(meta)
+ head.append(meta)
logging.debug('Injected `%s` tag into `%s` with content `%s`.', tag,
html_path, ca_manifest[tag])
if not soup('meta', {'charset': True}):
meta_charset = soup.new_tag('meta', charset='utf-8')
- soup.head.insert(0, meta_charset)
+ head.insert(0, meta_charset)
def insert_todos_into_file(js_path):
« no previous file with comments | « no previous file | src/caterpillar_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698