Update loose equal function, check toString value for primitive type (fix #4514) #4528

Merged
merged 1 commit into from Dec 21, 2016

Projects

None yet

4 participants

@defcc
Member
defcc commented Dec 20, 2016

fix #4514

+ const isObjectB = isObject(b)
+ if (isObjectA && isObjectB) {
+ return JSON.stringify(a) === JSON.stringify(b)
+ } else if (!isObjectA && !isObjectB) {
@kazupon
kazupon Dec 21, 2016 Member

LGTM.
(It may be better to check more strictly ... 😉 )

@dsonet
dsonet Dec 21, 2016 edited Contributor

It's loose equal. Which I think just add the 0 check is enough for primitive type cases. So we can skip unnecessary methods invoke here and keep it simple.

if(a === 0) {
  a = '0'
}
if(b === 0) {
  b = '0'
}
return a == b || (
     isObject(a) && isObject(b)
      ? JSON.stringify(a) === JSON.stringify(b)
      : false
 )
@defcc
defcc Dec 21, 2016 edited Member

We need strict equality for primitive type, e.g., '0' is equal to false. I'll update the test case like bellow

new Vue({
  data: {
    val: false,
    test: 0
  },
  template:
    '<div>' +
      '<input type="radio" value="" v-model="test">' +
      '<input type="radio" value="0" v-model="test">' +
      '<input type="radio" :value="val" v-model="test">' +
    '</div>'
}).$mount('#app')
@defcc
defcc Dec 22, 2016 Member

done via #4542

@yyx990803 yyx990803 merged commit 56bfa1d into vuejs:dev Dec 21, 2016

1 check passed

ci/circleci Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment