Skip to content

Commit

Permalink
fix(runtime-core): only trim string parameter when work with v-model …
Browse files Browse the repository at this point in the history
…on component (#5765)
  • Loading branch information
shadowings-zy committed Apr 21, 2022
1 parent 4a3237a commit d7e859f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/runtime-core/__tests__/componentEmits.spec.ts
Expand Up @@ -355,6 +355,28 @@ describe('component: emit', () => {
expect(fn2).toHaveBeenCalledWith('two')
})

test('only trim string parameter when work with v-model on component', () => {
const Foo = defineComponent({
render() {},
created() {
this.$emit('update:modelValue', ' foo ', { bar: ' bar ' })
}
})

const fn = jest.fn()
const Comp = () =>
h(Foo, {
modelValue: null,
modelModifiers: { trim: true },
'onUpdate:modelValue': fn
})

render(h(Comp), nodeOps.createElement('div'))

expect(fn).toHaveBeenCalledTimes(1)
expect(fn).toHaveBeenCalledWith('foo', { bar: ' bar ' })
})

test('isEmitListener', () => {
const options = {
click: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentEmits.ts
Expand Up @@ -121,7 +121,7 @@ export function emit(
}Modifiers`
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
if (trim) {
args = rawArgs.map(a => a.trim())
args = rawArgs.map(a => (typeof a === 'string' ? a.trim() : a))
} else if (number) {
args = rawArgs.map(toNumber)
}
Expand Down

0 comments on commit d7e859f

Please sign in to comment.