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:
committed by
Alexander Lichter
parent
a9d46888ce
commit
2adba84e58
@@ -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
|
||||
|
||||
@@ -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, '"'],
|
||||
[/'/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) {
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
import { metaInfoOptionKeys, disableOptionKeys } from './constants'
|
||||
import { isString, isArray, isObject } from './is-type'
|
||||
|
||||
export const serverSequences = [
|
||||
[/&/g, '&'],
|
||||
[/</g, '<'],
|
||||
[/>/g, '>'],
|
||||
[/"/g, '"'],
|
||||
[/'/g, ''']
|
||||
]
|
||||
|
||||
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,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'
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user