diff --git a/packages/pug-runtime/index.js b/packages/pug-runtime/index.js index 4d1bdbee0..d506ddb28 100644 --- a/packages/pug-runtime/index.js +++ b/packages/pug-runtime/index.js @@ -30,7 +30,9 @@ function pug_merge(a, b) { a[key] = (Array.isArray(valA) ? valA : [valA]).concat(b[key] || []); } else if (key === 'style') { var valA = pug_style(a[key]); + valA = valA && valA[valA.length - 1] !== ';' ? valA + ';' : valA; var valB = pug_style(b[key]); + valB = valB && valB[valB.length - 1] !== ';' ? valB + ';' : valB; a[key] = valA + valB; } else { a[key] = b[key]; @@ -109,10 +111,7 @@ function pug_style(val) { } return out; } else { - val += ''; - if (val[val.length - 1] !== ';') - return val + ';'; - return val; + return val + ''; } }; diff --git a/packages/pug-runtime/test/index.test.js b/packages/pug-runtime/test/index.test.js index 6618b63a7..c729b0c82 100644 --- a/packages/pug-runtime/test/index.test.js +++ b/packages/pug-runtime/test/index.test.js @@ -132,7 +132,7 @@ addTest('merge', function (merge) { addTest('style', function (style) { expect(style(null)).toBe(''); expect(style('')).toBe(''); - expect(style('foo: bar')).toBe('foo: bar;'); + expect(style('foo: bar')).toBe('foo: bar'); expect(style('foo: bar;')).toBe('foo: bar;'); expect(style({foo: 'bar'})).toBe('foo:bar;'); expect(style({foo: 'bar', baz: 'bash'})).toBe('foo:bar;baz:bash;'); diff --git a/packages/pug/test/cases-es2015/attr.html b/packages/pug/test/cases-es2015/attr.html index 5b9fbfbdd..fba8cc120 100644 --- a/packages/pug/test/cases-es2015/attr.html +++ b/packages/pug/test/cases-es2015/attr.html @@ -1 +1 @@ -
+
diff --git a/packages/pug/test/cases/styles.html b/packages/pug/test/cases/styles.html index 394953e32..251556ee4 100644 --- a/packages/pug/test/cases/styles.html +++ b/packages/pug/test/cases/styles.html @@ -7,11 +7,11 @@ +
+
-
-
-
+
diff --git a/packages/pug/test/output-es2015/attr.html b/packages/pug/test/output-es2015/attr.html index 25c479ac8..63a82c0d4 100644 --- a/packages/pug/test/output-es2015/attr.html +++ b/packages/pug/test/output-es2015/attr.html @@ -1,2 +1,2 @@ -
\ No newline at end of file +
\ No newline at end of file diff --git a/packages/pug/test/pug.test.js b/packages/pug/test/pug.test.js index 4fb073ae3..228dadbd9 100644 --- a/packages/pug/test/pug.test.js +++ b/packages/pug/test/pug.test.js @@ -371,8 +371,8 @@ describe('pug', function(){ assert.equal('', pug.render('a(href= "http://google.com", title= "Some : weird = title")')); assert.equal('', pug.render('label(for="name")')); assert.equal('', pug.render("meta(name= 'viewport', content='width=device-width')"), 'Test attrs that contain attr separators'); - assert.equal('
', pug.render("div(style='color= white')")); - assert.equal('
', pug.render("div(style='color: white')")); + assert.equal('
', pug.render("div(style='color= white')")); + assert.equal('
', pug.render("div(style='color: white')")); assert.equal('

', pug.render("p('class'='foo')"), 'Test keys with single quotes'); assert.equal('

', pug.render("p(\"class\"= 'foo')"), 'Test keys with double quotes'); @@ -389,10 +389,10 @@ describe('pug', function(){ assert.equal('', pug.render('meta(http-equiv="X-UA-Compatible", content="IE=edge,chrome=1")')); - assert.equal('
Foo
', pug.render("div(style= 'background: url(/images/test.png)') Foo")); - assert.equal('
Foo
', pug.render("div(style= 'background = url(/images/test.png)') Foo")); - assert.equal('
Foo
', pug.render("div(style= ['foo', 'bar'][0]) Foo")); - assert.equal('
Foo
', pug.render("div(style= { foo: 'bar', baz: 'raz' }['foo']) Foo")); + assert.equal('
Foo
', pug.render("div(style= 'background: url(/images/test.png)') Foo")); + assert.equal('
Foo
', pug.render("div(style= 'background = url(/images/test.png)') Foo")); + assert.equal('
Foo
', pug.render("div(style= ['foo', 'bar'][0]) Foo")); + assert.equal('
Foo
', pug.render("div(style= { foo: 'bar', baz: 'raz' }['foo']) Foo")); assert.equal('Foo', pug.render("a(href='abcdefg'.substr(3,3)) Foo")); assert.equal('Foo', pug.render("a(href={test: 'abcdefg'}.test.substr(3,3)) Foo")); assert.equal('Foo', pug.render("a(href={test: 'abcdefg'}.test.substr(3,[0,3][1])) Foo"));