Skip to content
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

fix(runtime-core): modifier .trim compatibility (fix #6711) #6713

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/runtime-core/__tests__/componentEmits.spec.ts
Expand Up @@ -355,6 +355,38 @@ describe('component: emit', () => {
expect(fn2).toHaveBeenCalledWith('two')
})

// #6711
test('.trim modifier only works with string parameters.', () => {
const Foo = defineComponent({
render() {},
created() {
this.$emit('update:modelValue', ' one ', { one: 'one' })
this.$emit('update:foo', ' two ', ['two'])
}
})

const fn1 = jest.fn()
const fn2 = jest.fn()

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

foo: null,
fooModifiers: { trim: true },
'onUpdate:foo': fn2
})

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

expect(fn1).toHaveBeenCalledTimes(1)
expect(fn1).toHaveBeenCalledWith('one', { one: 'one' })
expect(fn2).toHaveBeenCalledTimes(1)
expect(fn2).toHaveBeenCalledWith('two', ['two'])
})

test('.trim and .number modifiers should work with v-model on component', () => {
const Foo = defineComponent({
render() {},
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/componentEmits.ts
Expand Up @@ -9,6 +9,7 @@ import {
isFunction,
isObject,
isOn,
isString,
toNumber,
UnionToIntersection
} from '@vue/shared'
Expand Down Expand Up @@ -122,7 +123,7 @@ export function emit(
}Modifiers`
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
if (trim) {
args = rawArgs.map(a => a.trim())
args = rawArgs.map(a => (isString(a) ? a.trim() : a))
}
if (number) {
args = rawArgs.map(toNumber)
Expand Down