Merge pull request #1540 from bitwiseman/uri

Fixed support for data URI with test
This commit is contained in:
Liam Newman 2018-09-10 12:53:43 -07:00 committed by GitHub
commit 5aec460246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 1 deletions

View File

@ -373,7 +373,7 @@ Beautifier.prototype.beautify = function() {
this.print_string(this._ch);
this.eatWhitespace();
this._ch = this._input.next();
if (this._ch === ')' || this._ch === '"' || this._ch !== '\'') {
if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
this._input.back();
parenLevel++;
} else if (this._ch) {

View File

@ -370,6 +370,30 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'\topacity: 0.9;\n' +
'\tfilter: alpha(opacity=90);\n' +
'}');
// simple data uri base64 test
t(
'a { background: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=); }',
// -- output --
'a {\n' +
'\tbackground: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=);\n' +
'}');
// non-base64 data
t(
'a { background: url(data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E); }',
// -- output --
'a {\n' +
'\tbackground: url(data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E);\n' +
'}');
// Beautifier does not fix or mitigate bad data uri
t(
'a { background: url(data: image/gif base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=); }',
// -- output --
'a {\n' +
'\tbackground: url(data: image/gif base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=);\n' +
'}');
//============================================================

View File

@ -296,6 +296,30 @@ class CSSBeautifierTest(unittest.TestCase):
'\topacity: 0.9;\n' +
'\tfilter: alpha(opacity=90);\n' +
'}')
# simple data uri base64 test
t(
'a { background: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=); }',
# -- output --
'a {\n' +
'\tbackground: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=);\n' +
'}')
# non-base64 data
t(
'a { background: url(data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E); }',
# -- output --
'a {\n' +
'\tbackground: url(data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E);\n' +
'}')
# Beautifier does not fix or mitigate bad data uri
t(
'a { background: url(data: image/gif base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=); }',
# -- output --
'a {\n' +
'\tbackground: url(data: image/gif base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=);\n' +
'}')
#============================================================

View File

@ -165,6 +165,18 @@ exports.test_data = {
tests: [{
input: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity = 90);\n}',
output: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity=90);\n}'
}, {
comment: 'simple data uri base64 test',
input: 'a { background: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=); }',
output: 'a {\n\tbackground: url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=);\n}'
}, {
comment: 'non-base64 data',
input: 'a { background: url(data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E); }',
output: 'a {\n\tbackground: url(data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E);\n}'
}, {
comment: 'Beautifier does not fix or mitigate bad data uri',
input: 'a { background: url(data: image/gif base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=); }',
output: 'a {\n\tbackground: url(data: image/gif base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=);\n}'
}]
}, {
name: "Support simple language specific option inheritance/overriding",