Skip to content

fix(v-model): v-model ended with spaces #7735

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function genComponentModel (
if (trim) {
valueExpression =
`(typeof ${baseValueExpression} === 'string'` +
`? ${baseValueExpression}.trim()` +
`: ${baseValueExpression})`
`? ${baseValueExpression}.trim()` +
`: ${baseValueExpression})`
}
if (number) {
valueExpression = `_n(${valueExpression})`
Expand Down Expand Up @@ -69,6 +69,7 @@ type ModelParseResult = {

export function parseModel (val: string): ModelParseResult {
len = val.length
val = val.trim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be above the previous line 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true, I fixed this in the last commit


if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
index = val.lastIndexOf('.')
Expand Down
10 changes: 10 additions & 0 deletions test/unit/features/directives/model-text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ describe('Directive v-model text', () => {
}).then(done)
})

it('should not create a new property ended with spaces when', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test that fails without the fix above please? This one passes
Also, could you rename the test title to should work with extra whitespace properties or something similar, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand the part of the test. Do I create another pull request with only the test? Because the current test fails without this fix

const vm = new Vue({
data: {
test: 'b'
},
template: '<input v-model="test ">'
}).$mount()
expect(vm['test ']).toBe(undefined)
})

it('.lazy modifier', () => {
const vm = new Vue({
data: {
Expand Down