Skip to content

fix(compiler): support decode   in the value of prop and attribute #11563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/parser/html-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const isPlainTextElement = makeMap('script,style,textarea', true)
const reCache = {}

const decodingMap = {
' ': ' ',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
Expand All @@ -39,8 +40,8 @@ const decodingMap = {
'&#9;': '\t',
'&#39;': "'"
}
const encodedAttr = /&(?:lt|gt|quot|amp|#39);/g
const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g
const encodedAttr = /&(?:lt|gt|quot|amp|#39|nbsp);/g
const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|nbsp|#10|#9);/g

// #5992
const isIgnoreNewlineTag = makeMap('pre,textarea', true)
Expand Down
6 changes: 6 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,10 @@ describe('parser', () => {
expect(ast.children[2].type).toBe(3)
expect(ast.children[2].text).toBe('\ndef')
})

it(`should decode &nbsp; in the value of attribute`, () => {
const options = extend({}, baseOptions)
const ast = parse('<input value="white&nbsp;space" />', options)
expect(ast.attrsList[0].value).toBe('white space')
})
})