mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 00:00:33 +03:00
fix: only show boolean attrs with truthy value
This commit is contained in:
@@ -42,6 +42,7 @@ package-lock.json
|
|||||||
lib
|
lib
|
||||||
es
|
es
|
||||||
.vue-meta
|
.vue-meta
|
||||||
|
.nuxt
|
||||||
|
|
||||||
# examples yarn lock
|
# examples yarn lock
|
||||||
examples/yarn.lock
|
examples/yarn.lock
|
||||||
|
|||||||
@@ -52,7 +52,13 @@ export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type,
|
|||||||
const _attr = includes(dataAttributes, attr)
|
const _attr = includes(dataAttributes, attr)
|
||||||
? `data-${attr}`
|
? `data-${attr}`
|
||||||
: attr
|
: attr
|
||||||
const value = isUndefined(tag[attr]) || includes(booleanHtmlAttributes, attr) ? '' : tag[attr]
|
|
||||||
|
const isBooleanAttribute = includes(booleanHtmlAttributes, attr)
|
||||||
|
if (isBooleanAttribute && !tag[attr]) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = isBooleanAttribute ? '' : tag[attr]
|
||||||
newElement.setAttribute(_attr, value)
|
newElement.setAttribute(_attr, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ export default function tagGenerator(appId, { attribute, tagIDKeyName } = {}, ty
|
|||||||
prefix = 'data-'
|
prefix = 'data-'
|
||||||
}
|
}
|
||||||
|
|
||||||
return isUndefined(tag[attr]) || booleanHtmlAttributes.includes(attr)
|
const isBooleanAttr = booleanHtmlAttributes.includes(attr)
|
||||||
|
if (isBooleanAttr && !tag[attr]) {
|
||||||
|
return attrsStr
|
||||||
|
}
|
||||||
|
|
||||||
|
return isBooleanAttr
|
||||||
? `${attrsStr} ${prefix}${attr}`
|
? `${attrsStr} ${prefix}${attr}`
|
||||||
: `${attrsStr} ${prefix}${attr}="${tag[attr]}"`
|
: `${attrsStr} ${prefix}${attr}="${tag[attr]}"`
|
||||||
}, '')
|
}, '')
|
||||||
|
|||||||
@@ -71,4 +71,35 @@ describe('escaping', () => {
|
|||||||
__dangerouslyDisableSanitizersByTagID: { noscape: ['innerHTML'] }
|
__dangerouslyDisableSanitizersByTagID: { noscape: ['innerHTML'] }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.skip('special chars are escaped unless disabled by vmid', () => {
|
||||||
|
const component = new Vue({
|
||||||
|
metaInfo: {
|
||||||
|
title: 'Hello',
|
||||||
|
script: [
|
||||||
|
{ vmid: 'yescape', innerHTML: ['12', 'asd'] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(getMetaInfo(component, [[/&/g, '&']])).toEqual({
|
||||||
|
title: 'Hello',
|
||||||
|
titleChunk: 'Hello',
|
||||||
|
titleTemplate: '%s',
|
||||||
|
htmlAttrs: {},
|
||||||
|
headAttrs: {},
|
||||||
|
bodyAttrs: {},
|
||||||
|
meta: [],
|
||||||
|
base: [],
|
||||||
|
link: [],
|
||||||
|
style: [],
|
||||||
|
script: [
|
||||||
|
{ innerHTML: 'Hello & Goodbye', vmid: 'yescape' },
|
||||||
|
{ innerHTML: 'Hello & Goodbye', vmid: 'noscape' }
|
||||||
|
],
|
||||||
|
noscript: [],
|
||||||
|
__dangerouslyDisableSanitizers: [],
|
||||||
|
__dangerouslyDisableSanitizersByTagID: { noscape: ['innerHTML'] }
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -113,12 +113,12 @@ const metaInfoData = {
|
|||||||
script: {
|
script: {
|
||||||
add: {
|
add: {
|
||||||
data: [
|
data: [
|
||||||
{ src: 'src', async: true, defer: true, [defaultOptions.tagIDKeyName]: 'content' },
|
{ src: 'src', async: false, defer: true, [defaultOptions.tagIDKeyName]: 'content' },
|
||||||
{ src: 'src', async: true, defer: true, body: true }
|
{ src: 'src', async: false, defer: true, body: true }
|
||||||
],
|
],
|
||||||
expect: [
|
expect: [
|
||||||
'<script data-vue-meta="test" src="src" async defer data-vmid="content"></script>',
|
'<script data-vue-meta="test" src="src" defer data-vmid="content"></script>',
|
||||||
'<script data-vue-meta="test" src="src" async defer data-body="true"></script>'
|
'<script data-vue-meta="test" src="src" defer data-body="true"></script>'
|
||||||
],
|
],
|
||||||
test(side, defaultTest) {
|
test(side, defaultTest) {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user