Skip to content

Commit

Permalink
Fix bug where simultaneous edits could lose data
Browse files Browse the repository at this point in the history
The cause of the issue was normalization: U+0061 LATIN SMALL LETTER A
followed by U+0301 COMBINING ACUTE ACCENT was in the Mongo database (for
example), but what got saved into Mongo was U+00E1 LATIN SMALL LETTER A
WITH ACUTE. The diff algorithm naturally compared those two as different
(since it's doing a basic byte comparison on strings), and therefore a
delta update was being submitted which changed á to á. Mongo was
therefore writing that field's value in the database, accidentally
overwriting any previous edits to that field from a different user.

The answer is to normalize the pristineEntry value (the value that came
out of the database) before passing it to the diffing algorithm, so that
it's comparing NFC to NFC. With this change, I can no longer reproduce
the test case for #1248, which I was consistently reproducing before the
change. So although there might be other situations that can also cause
edits to be lost, I'm confident that the most mysterious one is fixed.
  • Loading branch information
rmunn committed Feb 22, 2022
1 parent cacc253 commit 81aea30
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export class LexiconEditorController implements angular.IController {
const pristineEntryForDiffing = this.removeCustomFieldsForDeltaUpdate(this.prepEntryForUpdate(this.pristineEntry));
const diffForUpdate = isNewEntry ? undefined : {
id: entryForUpdate.id,
_update_deep_diff: diff(pristineEntryForDiffing, entryForDiffing)
_update_deep_diff: diff(LexiconEditorController.normalizeStrings(pristineEntryForDiffing), entryForDiffing)
};
let entryOrDiff = isNewEntry ? entryForUpdate : diffForUpdate;
if (!isNewEntry && this.hasArrayChange(diffForUpdate._update_deep_diff)) {
Expand Down

0 comments on commit 81aea30

Please sign in to comment.