diff --git a/src/client/refresh.js b/src/client/refresh.js index 9c11e0b..c5d1136 100644 --- a/src/client/refresh.js +++ b/src/client/refresh.js @@ -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, '\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 diff --git a/src/server/inject.js b/src/server/inject.js index f094198..fa58e8c 100644 --- a/src/server/inject.js +++ b/src/server/inject.js @@ -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, '&'], - [//g, '>'], - [/"/g, '"'], - [/'/g, '''] - ] - /** * 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) { diff --git a/src/shared/escape.js b/src/shared/escaping.js similarity index 82% rename from src/shared/escape.js rename to src/shared/escaping.js index e190b7f..f790b7f 100644 --- a/src/shared/escape.js +++ b/src/shared/escaping.js @@ -1,8 +1,24 @@ import { metaInfoOptionKeys, disableOptionKeys } from './constants' import { isString, isArray, isObject } from './is-type' +export const serverSequences = [ + [/&/g, '&'], + [//g, '>'], + [/"/g, '"'], + [/'/g, '''] +] + +export const clientSequences = [ + [/&/g, '\u0026'], + [//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 = {} diff --git a/src/shared/getMetaInfo.js b/src/shared/getMetaInfo.js index 2e6d324..5574164 100644 --- a/src/shared/getMetaInfo.js +++ b/src/shared/getMetaInfo.js @@ -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' /**