mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-11 07:22:26 +03:00
fix: don't generate <title> tag if metaInfo.title is null or false (#409)
This commit is contained in:
committed by
Pim
parent
b150d82eec
commit
39ef28752b
@@ -8,6 +8,9 @@
|
||||
export default function titleGenerator (appId, { attribute } = {}, type, data) {
|
||||
return {
|
||||
text () {
|
||||
if (!data) {
|
||||
return ''
|
||||
}
|
||||
return `<${type}>${data}</${type}>`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isString, isArray, isObject } from '../utils/is-type'
|
||||
import { isString, isArray, isPureObject } from '../utils/is-type'
|
||||
import { includes } from '../utils/array'
|
||||
import { metaInfoOptionKeys, disableOptionKeys } from './constants'
|
||||
|
||||
@@ -55,11 +55,11 @@ export function escape (info, options, escapeOptions) {
|
||||
escaped[key] = doEscape(value)
|
||||
} else if (isArray(value)) {
|
||||
escaped[key] = value.map((v) => {
|
||||
return isObject(v)
|
||||
return isPureObject(v)
|
||||
? escape(v, options, escapeOptions)
|
||||
: doEscape(v)
|
||||
})
|
||||
} else if (isObject(value)) {
|
||||
} else if (isPureObject(value)) {
|
||||
escaped[key] = escape(value, options, escapeOptions)
|
||||
} else {
|
||||
escaped[key] = value
|
||||
|
||||
@@ -15,6 +15,10 @@ export function isObject (arg) {
|
||||
return typeof arg === 'object'
|
||||
}
|
||||
|
||||
export function isPureObject (arg) {
|
||||
return typeof arg === 'object' && arg !== null
|
||||
}
|
||||
|
||||
export function isFunction (arg) {
|
||||
return typeof arg === 'function'
|
||||
}
|
||||
|
||||
@@ -39,6 +39,31 @@ describe('escaping', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('null title is left as it is', () => {
|
||||
const component = new Vue({
|
||||
metaInfo: {
|
||||
title: null
|
||||
}
|
||||
})
|
||||
|
||||
expect(getMetaInfo(component, [[/&/g, '&']])).toEqual({
|
||||
title: null,
|
||||
titleChunk: '',
|
||||
titleTemplate: '%s',
|
||||
htmlAttrs: {},
|
||||
headAttrs: {},
|
||||
bodyAttrs: {},
|
||||
meta: [],
|
||||
base: [],
|
||||
link: [],
|
||||
style: [],
|
||||
script: [],
|
||||
noscript: [],
|
||||
__dangerouslyDisableSanitizers: [],
|
||||
__dangerouslyDisableSanitizersByTagID: {}
|
||||
})
|
||||
})
|
||||
|
||||
test('special chars are escaped unless disabled by vmid', () => {
|
||||
const component = new Vue({
|
||||
metaInfo: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import _generateServerInjector from '../../src/server/generateServerInjector'
|
||||
import { defaultOptions } from '../../src/shared/constants'
|
||||
import metaInfoData from '../utils/meta-info-data'
|
||||
import { titleGenerator } from '../../src/server/generators'
|
||||
|
||||
const generateServerInjector = (type, data) => _generateServerInjector('test', defaultOptions, type, data)
|
||||
|
||||
@@ -59,3 +60,10 @@ describe('generators', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('title generator should return an empty string when title is null', () => {
|
||||
const title = null
|
||||
const generatedTitle = titleGenerator(0, {}, 'title', title)
|
||||
|
||||
expect(generatedTitle.text()).toEqual('')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user