Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows empty attributes in html tag helper #36

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

Xaviju
Copy link
Contributor

@Xaviju Xaviju commented Jul 31, 2018

Fixes this issue -> hexojs/hexo#3222

@coveralls
Copy link

coveralls commented Jul 31, 2018

Coverage Status

Coverage increased (+0.009%) to 96.884% when pulling d05ba8b on Xaviju:issue/3222/image-tag-allow-empty into 2b5e282 on hexojs:master.

@Xaviju Xaviju force-pushed the issue/3222/image-tag-allow-empty branch from 675e9c3 to b8a6b29 Compare July 31, 2018 15:15
JLHwung
JLHwung previously approved these changes Aug 1, 2018
lib/html_tag.js Outdated
@@ -6,7 +6,7 @@ function htmlTag(tag, attrs, text) {
var result = '<' + tag;

for (var i in attrs) {
if (attrs[i]) result += ' ' + i + '="' + attrs[i] + '"';
if (attrs[i] || attrs[i] === '') result += ' ' + i + '="' + attrs[i] + '"';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we use stricter attrs[i] !== undefined && attrs[i] !== null on this check.

Copy link
Contributor Author

@Xaviju Xaviju Aug 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an error already if an attribute is not defined. Should I add the test?

it('tag + empty attr', function() {
    try {
      htmlTag('img', {
        src: 'http://placekitten.com/200/300',
        hidden
      });
    } catch (err) {
      err.should.have.property('message', 'hidden is not defined');
    }
  });

or

it('tag + empty attr', function() {
    try {
      htmlTag('img', {
        src: 'http://placekitten.com/200/300',
        alt: null
      });
    } catch (err) {
      err.should.have.property('message', 'alt is not defined');
    }
  });

@Xaviju Xaviju force-pushed the issue/3222/image-tag-allow-empty branch 2 times, most recently from 2b5ce8e to 576289e Compare August 1, 2018 15:57
@Xaviju
Copy link
Contributor Author

Xaviju commented Aug 1, 2018

Thinking it twice, just adding the conditions you suggested, all possible valid attributes are working as expected. I've added a few tests to ensure that works properly.

@NoahDragon
Copy link
Member

Could you please fix the error in travis-ci?

@Xaviju Xaviju force-pushed the issue/3222/image-tag-allow-empty branch from 576289e to d05ba8b Compare August 28, 2018 16:28
@Xaviju
Copy link
Contributor Author

Xaviju commented Aug 28, 2018

@NoahDragon should be fixed now

@NoahDragon
Copy link
Member

@Xaviju Great, thank you.

Copy link
Member

@NoahDragon NoahDragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NoahDragon NoahDragon merged commit 38933b6 into hexojs:master Aug 29, 2018
@Xaviju Xaviju deleted the issue/3222/image-tag-allow-empty branch August 30, 2018 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants