mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-18 05:00:34 +03:00
feat: support json content (without disabling sanitizers) (#415)
* feat: add json prop to bypass sanitizers * chore: fix lint * feat: escape keys as well test: fix json escaping * add escapeKeys into escapeOptions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import _getMetaInfo from '../../src/shared/getMetaInfo'
|
||||
import { loadVueMetaPlugin } from '../utils'
|
||||
import { defaultOptions } from '../../src/shared/constants'
|
||||
import { serverSequences } from '../../src/shared/escaping'
|
||||
|
||||
const getMetaInfo = (component, escapeSequences) => _getMetaInfo(defaultOptions, component, escapeSequences)
|
||||
|
||||
@@ -96,4 +97,43 @@ describe('escaping', () => {
|
||||
__dangerouslyDisableSanitizersByTagID: { noscape: ['innerHTML'] }
|
||||
})
|
||||
})
|
||||
|
||||
test('json is still safely escaped', () => {
|
||||
const component = new Vue({
|
||||
metaInfo: {
|
||||
script: [
|
||||
{
|
||||
json: {
|
||||
perfectlySave: '</script><p class="unsafe">This is safe</p><script>',
|
||||
'</script>unsafeKey': 'This is also still safe'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
expect(getMetaInfo(component, serverSequences)).toEqual({
|
||||
title: undefined,
|
||||
titleChunk: '',
|
||||
titleTemplate: '%s',
|
||||
htmlAttrs: {},
|
||||
headAttrs: {},
|
||||
bodyAttrs: {},
|
||||
meta: [],
|
||||
base: [],
|
||||
link: [],
|
||||
style: [],
|
||||
script: [
|
||||
{
|
||||
json: {
|
||||
perfectlySave: '</script><p class="unsafe">This is safe</p><script>',
|
||||
'</script>unsafeKey': 'This is also still safe'
|
||||
}
|
||||
}
|
||||
],
|
||||
noscript: [],
|
||||
__dangerouslyDisableSanitizers: [],
|
||||
__dangerouslyDisableSanitizersByTagID: {}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user