Skip to content

Commit 750bde8

Browse files
authored
Fix bug where simultaneous edits could lose data (#1313)
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.
1 parent cacc253 commit 750bde8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/angular-app/languageforge/lexicon/editor/editor.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export class LexiconEditorController implements angular.IController {
377377
const pristineEntryForDiffing = this.removeCustomFieldsForDeltaUpdate(this.prepEntryForUpdate(this.pristineEntry));
378378
const diffForUpdate = isNewEntry ? undefined : {
379379
id: entryForUpdate.id,
380-
_update_deep_diff: diff(pristineEntryForDiffing, entryForDiffing)
380+
_update_deep_diff: diff(LexiconEditorController.normalizeStrings(pristineEntryForDiffing), entryForDiffing)
381381
};
382382
let entryOrDiff = isNewEntry ? entryForUpdate : diffForUpdate;
383383
if (!isNewEntry && this.hasArrayChange(diffForUpdate._update_deep_diff)) {

0 commit comments

Comments
 (0)