Skip to content

Commit

Permalink
Fixed support for data URI with test
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 8, 2018
1 parent 930c050 commit ac6450f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/css/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions js/test/generated/beautify-css-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
'}');


//============================================================
Expand Down
24 changes: 24 additions & 0 deletions python/cssbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,30 @@ def testGenerated(self):
'\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' +
'}')


#============================================================
Expand Down
12 changes: 12 additions & 0 deletions test/data/css/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ac6450f

Please sign in to comment.