Skip to content

Commit

Permalink
fix(htmlTag): String() before match() for scalar values (#176)
Browse files Browse the repository at this point in the history
* toString() before match() for scalar values.

* Update lib/html_tag.js

Co-Authored-By: Sukka <[email protected]>

* Fixed misplaced negation operator

Co-authored-by: Sukka <[email protected]>
  • Loading branch information
KentarouTakeda and SukkaW committed Jan 26, 2020
1 parent ddcdc31 commit 4e7c24e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/html_tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function htmlTag(tag, attrs, text, escape = true) {
if (attrs[i] == null) result += '';
else {
if (i.match(regexUrl)
|| (tag === 'meta' && !attrs[i].match(regexMeta) && Object.values(attrs)[0].match(regexMeta))) {
|| (tag === 'meta' && !String(attrs[i]).match(regexMeta) && Object.values(attrs)[0].match(regexMeta))) {
result += ` ${escapeHTML(i)}="${encodeURL(attrs[i])}"`;
} else if (attrs[i] === true || i === attrs[i]) result += ` ${escapeHTML(i)}`;
else if (i.match(/srcset$/i)) result += ` ${escapeHTML(i)}="${encSrcset(attrs[i])}"`;
Expand Down
7 changes: 7 additions & 0 deletions test/html_tag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,11 @@ describe('htmlTag', () => {
content: 'bar " baz'
}).should.eql('<meta name="foo image" content="bar &quot; baz">');
});

it('meta tag - numeric property', () => {
htmlTag('meta', {
property: 'fb:app_id',
content: 123456789
}).should.eql('<meta property="fb:app_id" content="123456789">');
});
});

0 comments on commit 4e7c24e

Please sign in to comment.