Skip to content

Commit

Permalink
Merge pull request #454 from timmorey/main
Browse files Browse the repository at this point in the history
Prevent loss of characters in case of false end-partial-match
  • Loading branch information
ef4 authored Oct 10, 2021
2 parents a88004f + ba2b46a commit 450d321
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/ember-auto-import/ts/analyzer-syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ class Deserializer {
meta: state.meta.join(''),
};
} else {
// partial match failed to complete
// partial match failed to complete, so we need to replace the partial
// marker match we stripped off the last chunk
this.state = {
type: 'finding-end',
meta: state.meta,
meta: [...state.meta, MARKER.slice(0, state.partialMatch)],
};
return this.consumeChunk(chunk);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/ember-auto-import/ts/tests/analyzer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,17 @@ Qmodule('analyzer-deserialize', function () {
let result = await deserialize(source([`stuff stuff stuff ${meta.slice(0, -2)}`, meta.slice(-2)]));
assert.deepEqual(result, sampleData());
});

test('false end marker at end of chunk', async function (assert) {
const meta = serialize(sampleData());
assert.ok(
meta.slice(MARKER.length, -MARKER.length).indexOf(MARKER[0]) > -1,
'serialized sample data must contain first character of MARKER somewhere between boundary markers for test to have meaning'
);
const slicePos = meta.slice(MARKER.length, -MARKER.length).indexOf(MARKER[0]) + MARKER.length + 1;
const result = await deserialize(
source([`stuff stuff stuff ${meta.slice(0, slicePos)}`, `${meta.slice(slicePos)} stuff stuff`])
);
assert.deepEqual(result, sampleData());
});
});

0 comments on commit 450d321

Please sign in to comment.