-
Notifications
You must be signed in to change notification settings - Fork 464
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
Type issue in RLEEncoder #448
Comments
I don't know what Maybe something like a method: calcSum(value) {
if (typeof value === 'number') return value;
if (value === null) return 0;
return value.length;
} Used in the three places where this same calculation is being done if (sumValues) sum += sumShift ? this.calcSum(firstValue) >>> sumShift : this.calcSum(firstValue); Or whatever the value of a string should be in this case. |
By the way, the reason there is a string at all comes from https://github.com/automerge/automerge/blob/08a456cc2ddc79d8c2f35953db0f1fd8ed418d0f/backend/encoding.js#L889-L903 As a sidenote, |
Hi @Brian-McBride, I believe |
Looking through the code, there is this line (repeated a few times)
https://github.com/automerge/automerge/blob/08a456cc2ddc79d8c2f35953db0f1fd8ed418d0f/backend/encoding.js#L695
sum
which is a number (defined above aslet sum = 0
.sumShift
can be undefined. This can be solved earlier in the code withconst { count, sumValues, sumShift = 0 } = options;
firstValue
is returned fromdecoder.readValue()
that has way too many types: string, number, null, undefined, voidA little cleanup in the decoder reduces the return types to
string | number | null
filtering down to the line in question wherefirstValue
can be of a number or string type.anyString >>> anyNumber
has a lot of side effects. It really just depends if the value can be cast to a number. If it can be cast, it will work as expected. If it can't it will return0
. Returning zero isn't probably correct assum
will not be incremented as a number would. Worse though, ifsum += sumShift
is falsey, then we end up with sum adding a string to0
. Now we aren't a number but0some-text-string
.Am I wrong here? Or does the RLEEncoder basically incorrectly generate the
sum
of strings when usingsumValues
?The text was updated successfully, but these errors were encountered: