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(Transition): fix validate duration #1188

Merged
merged 1 commit into from
May 18, 2020
Merged
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
10 changes: 5 additions & 5 deletions packages/runtime-dom/src/components/Transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getCurrentInstance,
callWithAsyncErrorHandling
} from '@vue/runtime-core'
import { isObject } from '@vue/shared'
import { isObject, toNumber } from '@vue/shared'
import { ErrorCodes } from 'packages/runtime-core/src/errorHandling'

const TRANSITION = 'transition'
Expand Down Expand Up @@ -165,15 +165,15 @@ function normalizeDuration(
if (duration == null) {
return null
} else if (isObject(duration)) {
return [toNumber(duration.enter), toNumber(duration.leave)]
return [NumberOf(duration.enter), NumberOf(duration.leave)]
} else {
const n = toNumber(duration)
const n = NumberOf(duration)
return [n, n]
}
}

function toNumber(val: unknown): number {
const res = Number(val || 0)
function NumberOf(val: unknown): number {
Copy link
Member Author

@underfin underfin May 15, 2020

Choose a reason for hiding this comment

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

Bug description:
When val = string => res = NaN => throw is NaN. This should throw isn't a number.
When val = NaN => res = 0 => check pass. This shold throw is NaN.

const res = toNumber(val)
if (__DEV__) validateDuration(res)
return res
}
Expand Down
13 changes: 7 additions & 6 deletions packages/runtime-dom/src/directives/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import {
warn
} from '@vue/runtime-core'
import { addEventListener } from '../modules/events'
import { isArray, looseEqual, looseIndexOf, invokeArrayFns } from '@vue/shared'
import {
isArray,
looseEqual,
looseIndexOf,
invokeArrayFns,
toNumber
} from '@vue/shared'

type AssignerFn = (value: any) => void

Expand All @@ -33,11 +39,6 @@ function trigger(el: HTMLElement, type: string) {
el.dispatchEvent(e)
}

function toNumber(val: string): number | string {
const n = parseFloat(val)
return isNaN(n) ? val : n
}

type ModelDirective<T> = ObjectDirective<T & { _assign: AssignerFn }>

// We are exporting the v-model runtime directly as vnode hooks so that it can
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,8 @@ export const def = (obj: object, key: string | symbol, value: any) => {
value
})
}

export const toNumber = (val: any): any => {
const n = parseFloat(val)
return isNaN(n) ? val : n
}