kpdecker / jsdiff

A javascript text differencing implementation.
BSD 3-Clause "New" or "Revised" License
7.75k stars 491 forks source link

Race condition with this.options in async mode? #477

Closed ExplodingCabbage closed 5 months ago

ExplodingCabbage commented 6 months ago

It looks to me like the various diffing functions like diffLines each have a single Diff instance they use, and this is stateful - it has an options property that gets overwritten each time you call the diff method. But the diff method can be asynchronous when used with the callback option. That presumably means (I haven't tested yet; will need to create a test case demonstrating this & add it to the test suite) that if you were to call the same diffing method again before the asynchronous execution kicked off by a previous call had finished, you could modify the options seen by the in-progress previous call and thus affect its result.