diff --git a/lib/html_tag.js b/lib/html_tag.js
index 173f9077..85510fa7 100644
--- a/lib/html_tag.js
+++ b/lib/html_tag.js
@@ -6,7 +6,10 @@ function htmlTag(tag, attrs, text) {
var result = '<' + tag;
for (var i in attrs) {
- if (attrs[i]) result += ' ' + i + '="' + attrs[i] + '"';
+ if (
+ attrs[i] !== undefined
+ && attrs[i] !== null
+ ) result += ' ' + i + '="' + attrs[i] + '"';
}
result += text == null ? '>' : '>' + text + '' + tag + '>';
diff --git a/test/scripts/html_tag.js b/test/scripts/html_tag.js
index b079b81e..4bf9182b 100644
--- a/test/scripts/html_tag.js
+++ b/test/scripts/html_tag.js
@@ -27,6 +27,34 @@ describe('htmlTag', function() {
}, 'My blog').should.eql('My blog');
});
+ it('tag + empty ALT attr', function() {
+ htmlTag('img', {
+ src: 'http://placekitten.com/200/300',
+ alt: ''
+ }).should.eql('
');
+ });
+
+ it('passing a zero as attribute', function() {
+ htmlTag('a', {
+ href: 'http://zespia.tw',
+ tabindex: 0
+ }, 'My blog').should.eql('My blog');
+ });
+
+ it('passing a null alt attribute', function() {
+ htmlTag('a', {
+ href: 'http://zespia.tw',
+ alt: null
+ }, 'My blog').should.eql('My blog');
+ });
+
+ it('passing a undefined alt attribute', function() {
+ htmlTag('a', {
+ href: 'http://zespia.tw',
+ alt: undefined
+ }, 'My blog').should.eql('My blog');
+ });
+
it('tag is required', function() {
try {
htmlTag();