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

Unified Diff: grit/format/html_inline.py

Issue 10795100: Accept CSS url()s without quotes. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 8 years, 5 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 | grit/gather/chrome_html.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/html_inline.py
diff --git a/grit/format/html_inline.py b/grit/format/html_inline.py
index a6866365a1384d1c20b197ded9cf97e7dca27dae..922f6c5beb907ec558e94ae2b413979f955a8833 100755
--- a/grit/format/html_inline.py
+++ b/grit/format/html_inline.py
@@ -81,8 +81,13 @@ def SrcInlineAsDataURL(
mimetype = mimetypes.guess_type(filename)[0] or 'text/plain'
inline_data = base64.standard_b64encode(util.ReadFile(filepath, util.BINARY))
- prefix = src_match.string[src_match.start():src_match.start('filename')-1]
- return "%s\"data:%s;base64,%s\"" % (prefix, mimetype, inline_data)
+ prefix = src_match.string[src_match.start():src_match.start('filename')]
+ suffix = src_match.string[src_match.end('filename'):src_match.end()]
+ if prefix and prefix[-1] in '\'"':
+ prefix = prefix[:-1]
+ if suffix and suffix[0] in '\'"':
+ suffix = suffix[1:]
+ return '%s"data:%s;base64,%s"%s' % (prefix, mimetype, inline_data, suffix)
class InlinedData:
@@ -237,18 +242,18 @@ def DoInline(
"""Helper function that inlines external images in CSS backgrounds."""
# Replace contents of url() for css attributes: content, background,
# or *-image.
- return re.sub('(?:content|background|[\w-]*-image):[^;]*' +
- '(?:url\((?:\'|\")([^"\'\)\(]*)(?:\'|\")\)|' +
+ return re.sub('(content|background|[\w-]*-image):[^;]*' +
+ '(url\((?P<quote1>"|\'|)[^"\'()]*(?P=quote1)\)|' +
'image-set\(' +
- '([ ]*url\((?:\'|\")([^"\'\)\(]*)(?:\'|\")\)' +
- '[ ]*[0-9.]*x[ ]*(,[ ]*)?)*\))',
+ '([ ]*url\((?P<quote2>"|\'|)[^"\'()]*(?P=quote2)\)' +
+ '[ ]*[0-9.]*x[ ]*(,[ ]*)?)+\))',
lambda m: InlineCSSUrls(m, filepath),
text)
def InlineCSSUrls(src_match, filepath=input_filepath):
"""Helper function that inlines each url on a CSS image rule match."""
# Replace contents of url() references in matches.
- return re.sub('url\((?:\'|\")(?P<filename>[^"\'\)\(]*)(?:\'|\")',
+ return re.sub('url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)\)',
lambda m: SrcReplace(m, filepath),
src_match.group(0))
« no previous file with comments | « no previous file | grit/gather/chrome_html.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698