share/ShareJS — pull request #276 by aslakhellesoy (2013-11-12 22:48:10+00:00)
Title: Cannot edit empty document. Ensure Doc.snapshot is never undefined

I'm afraid I don't have a test for this, but here is how to reproduce the bug I'm fixing:

* Clone https://github.com/share/share-codemirror
* Follow instructions to bring up the example server - `examples/server.js`
* Open a browser and delete all text
* Type a single letter and see the error in the console: `Uncaught Error: Snapshot should be a string`

The root cause is that `this.snapshot` has the value `undefined` because `data.data=""` is falsey in JavaScript.

There might be other places in the code where similar precautions should be made - I haven't checked. At least this solves the problem where an empty document cannot be edited.