mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-05 13:38:18 +08:00
Avoid double-decoding on attribute value (#4797)
* Use a single `replace` instead so that we could avoid the double-decoding issue,i.e. get `"` after decoding `"` while `"` is expected. * Don't instantiate RegExp on every call
This commit is contained in:
parent
af1ec1ba99
commit
d14bd64143
@ -49,21 +49,19 @@ let IS_REGEX_CAPTURING_BROKEN = false
|
||||
const isScriptOrStyle = makeMap('script,style', true)
|
||||
const reCache = {}
|
||||
|
||||
const ltRE = /</g
|
||||
const gtRE = />/g
|
||||
const nlRE = / /g
|
||||
const ampRE = /&/g
|
||||
const quoteRE = /"/g
|
||||
const decodingMap = {
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
'&': '&',
|
||||
' ': '\n'
|
||||
}
|
||||
const encodedAttr = /&(lt|gt|quot|amp);/g
|
||||
const encodedAttrWithNewLines = /&(lt|gt|quot|amp|#10);/g
|
||||
|
||||
function decodeAttr (value, shouldDecodeNewlines) {
|
||||
if (shouldDecodeNewlines) {
|
||||
value = value.replace(nlRE, '\n')
|
||||
}
|
||||
return value
|
||||
.replace(ltRE, '<')
|
||||
.replace(gtRE, '>')
|
||||
.replace(ampRE, '&')
|
||||
.replace(quoteRE, '"')
|
||||
const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr
|
||||
return value.replace(re, match => decodingMap[match])
|
||||
}
|
||||
|
||||
export function parseHTML (html, options) {
|
||||
|
Loading…
Reference in New Issue
Block a user