ottypes / json0

Version 0 of the JSON OT type
447 stars 64 forks source link

JSON transform has an error branch condition #50

Open wss534857356 opened 12 months ago

wss534857356 commented 12 months ago

https://github.com/ottypes/json0/blob/90a3ae26364c4fa3b19b6df34dad46707a704421/lib/json0.js#L595

seems to have a wrong branch condition.First, it needs to be judged at the top layer that otherTo is not equal to otherFrom:

if (otherFrom !== otherTo) {
          // if otherFrom == otherTo, we don't need to change our op.

and then judge that to must be equal to otherTo, and to must be equal to otherFrom,

...
            } else if (to === otherTo) {
              // if we're both moving in the same direction, tie break
              if ((otherTo > otherFrom && to > from) ||
                  (otherTo < otherFrom && to < from)) {
                if (type === 'right') c.lm++;
              } else {
                if (to > from) c.lm++;
                else if (to === otherFrom) c.lm--;
              }
            }
...