2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-27 22:24:04 +03:00

refactor: combine escape info

This commit is contained in:
pimlie
2019-03-10 11:48:23 +01:00
committed by Alexander Lichter
parent a9d46888ce
commit 2adba84e58
4 changed files with 22 additions and 20 deletions
+2 -9
View File
@@ -1,16 +1,9 @@
import getMetaInfo from '../shared/getMetaInfo'
import { isFunction } from '../shared/is-type'
import { clientSequences } from '../shared/escaping'
import updateClientMetaInfo from './updateClientMetaInfo'
export default function _refresh(options = {}) {
const escapeSequences = [
[/&/g, '\u0026'],
[/</g, '\u003c'],
[/>/g, '\u003e'],
[/"/g, '\u0022'],
[/'/g, '\u0027']
]
/**
* When called, will update the current meta info with new meta info.
* Useful when updating meta info as the result of an asynchronous
@@ -22,7 +15,7 @@ export default function _refresh(options = {}) {
* @return {Object} - new meta info
*/
return function refresh() {
const metaInfo = getMetaInfo(options, this.$root, escapeSequences)
const metaInfo = getMetaInfo(options, this.$root, clientSequences)
const tags = updateClientMetaInfo(options, metaInfo)
// emit "event" with new info
+2 -9
View File
@@ -1,16 +1,9 @@
import getMetaInfo from '../shared/getMetaInfo'
import { metaInfoOptionKeys } from '../shared/constants'
import { serverSequences } from '../shared/escaping'
import generateServerInjector from './generateServerInjector'
export default function _inject(options = {}) {
const escapeSequences = [
[/&/g, '&amp;'],
[/</g, '&lt;'],
[/>/g, '&gt;'],
[/"/g, '&quot;'],
[/'/g, '&#x27;']
]
/**
* Converts the state of the meta info object such that each item
* can be compiled to a tag string on the server
@@ -20,7 +13,7 @@ export default function _inject(options = {}) {
*/
return function inject() {
// get meta info with sensible defaults
const metaInfo = getMetaInfo(options, this.$root, escapeSequences)
const metaInfo = getMetaInfo(options, this.$root, serverSequences)
// generate server injectors
for (const key in metaInfo) {
@@ -1,8 +1,24 @@
import { metaInfoOptionKeys, disableOptionKeys } from './constants'
import { isString, isArray, isObject } from './is-type'
export const serverSequences = [
[/&/g, '&amp;'],
[/</g, '&lt;'],
[/>/g, '&gt;'],
[/"/g, '&quot;'],
[/'/g, '&#x27;']
]
export const clientSequences = [
[/&/g, '\u0026'],
[/</g, '\u003c'],
[/>/g, '\u003e'],
[/"/g, '\u0022'],
[/'/g, '\u0027']
]
// sanitizes potentially dangerous characters
export default function escape(info, options, escapeOptions) {
export function escape(info, options, escapeOptions) {
const { tagIDKeyName } = options
const { doEscape = v => v } = escapeOptions
const escaped = {}
+1 -1
View File
@@ -1,7 +1,7 @@
import applyTemplate from './applyTemplate'
import { defaultInfo, disableOptionKeys } from './constants'
import { ensureIsArray } from './ensure'
import escape from './escape'
import { escape } from './escaping'
import getComponentOption from './getComponentOption'
/**