Skip to content
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

fix(web): don't crash if second transform is null #12860

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions web/src/engine/predictive-text/templates/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function applyTransform(transform: Transform, context: Context): Context
export function buildMergedTransform(first: Transform, second: Transform): Transform {
// These exist to avoid parameter mutation.
let mergedFirstInsert: string = first.insert;
if (!second) {
// can happen if we don't have a distribution or an empty transform
return first;
}
let mergedSecondDelete: number = second.deleteLeft;

// The 'fun' case: the second Transform wants to delete something from the first.
Expand Down
10 changes: 10 additions & 0 deletions web/src/engine/predictive-text/templates/tests/common.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ describe('Common utility functions', function() {
let mergedTransform = models.buildMergedTransform(apple, banana);
assert.deepEqual(mergedTransform, final);
});

it('empty second transform', () => { // #12494
let apple = {
insert: 'apple',
deleteLeft: 0
};

let mergedTransform = models.buildMergedTransform(apple, null);
assert.deepEqual(mergedTransform, apple);
});
});

describe('transformToSuggestion', function() {
Expand Down
Loading