2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-17 05:19:37 +03:00

fix: support falsy values in eg body attributes (fix: #535)

This commit is contained in:
pimlie
2020-04-05 11:39:04 +02:00
parent 3ecaf28e33
commit 1ef41080e7
3 changed files with 12 additions and 8 deletions
+3
View File
@@ -20,6 +20,9 @@ new Vue({
headAttrs: {
test: true
},
bodyAttrs: {
tabIndex: 0
},
meta: [
{ name: 'description', content: 'Hello', vmid: 'test' }
],
+3 -3
View File
@@ -28,7 +28,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) {
// remove attributes from the map
// which have been removed for this appId
for (const attr in data) {
if (data[attr] && appId in data[attr]) {
if (data[attr] !== undefined && appId in data[attr]) {
toUpdate.push(attr)
if (!attrs[attr]) {
@@ -43,7 +43,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) {
if (!attrData || attrData[appId] !== attrs[attr]) {
toUpdate.push(attr)
if (attrs[attr]) {
if (attrs[attr] !== undefined) {
data[attr] = data[attr] || {}
data[attr][appId] = attrs[attr]
}
@@ -61,7 +61,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) {
if (attrValues.length) {
const attrValue = includes(booleanHtmlAttributes, attr) && attrValues.some(Boolean)
? ''
: attrValues.filter(Boolean).join(' ')
: attrValues.filter(v => v !== undefined).join(' ')
tag.setAttribute(attr, attrValue)
} else {
+6 -5
View File
@@ -270,8 +270,8 @@ const metaInfoData = {
},
bodyAttrs: {
add: {
data: { foo: 'bar', fizz: ['fuzz', 'fozz'] },
expect: ['<body foo="bar" fizz="fuzz fozz" data-vue-meta="%7B%22foo%22:%7B%22ssr%22:%22bar%22%7D,%22fizz%22:%7B%22ssr%22:%5B%22fuzz%22,%22fozz%22%5D%7D%7D">'],
data: { foo: 'bar', fizz: ['fuzz', 'fozz'], falsy: 0 },
expect: ['<body foo="bar" fizz="fuzz fozz" falsy="0" data-vue-meta="%7B%22foo%22:%7B%22ssr%22:%22bar%22%7D,%22fizz%22:%7B%22ssr%22:%5B%22fuzz%22,%22fozz%22%5D%7D,%22falsy%22:%7B%22ssr%22:0%7D%7D">'],
test (side, defaultTest) {
return () => {
if (side === 'client') {
@@ -284,7 +284,8 @@ const metaInfoData = {
expect(attributeMap).toEqual({
bodyAttrs: {
foo: { ssr: 'bar' },
fizz: { ssr: ['fuzz', 'fozz'] }
fizz: { ssr: ['fuzz', 'fozz'] },
falsy: { ssr: 0 }
}
})
}
@@ -298,7 +299,7 @@ const metaInfoData = {
return () => {
defaultTest()
expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'baz' }, fizz: {} } })
expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'baz' }, fizz: {}, falsy: {} } })
}
}
},
@@ -309,7 +310,7 @@ const metaInfoData = {
return () => {
defaultTest()
expect(attributeMap).toEqual({ bodyAttrs: { foo: {}, fizz: {} } })
expect(attributeMap).toEqual({ bodyAttrs: { foo: {}, fizz: {}, falsy: {} } })
}
}
}