diff --git a/src/compiler/parser/html-parser.js b/src/compiler/parser/html-parser.js index 087aef66970..3be1e09f44b 100644 --- a/src/compiler/parser/html-parser.js +++ b/src/compiler/parser/html-parser.js @@ -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) {