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

Multiline strings cause crash on read #10

Closed
aral opened this issue Jul 29, 2021 · 0 comments
Closed

Multiline strings cause crash on read #10

aral opened this issue Jul 29, 2021 · 0 comments

Comments

@aral
Copy link
Contributor

aral commented Jul 29, 2021

Reproduction

import JSDB from '@small-tech/jsdb'

const test = JSDB.open('test')

test.table = {
  s: `a
  multiline
  string`
}

console.log(test.table)

What happens

First run: OK (no bug in creation). Output:

   💾    ❨JSDB❩ No database found at /home/aral/sandbox/jsdb-multiline-text-test/test; creating it.
   💾    ❨JSDB❩ Creating and persisting table table…
   💾    ❨JSDB❩  ╰─ Created and persisted table in 1.224 ms.
   💾    ❨JSDB❩ Table table initialised.
{ s: 'a\n  multiline\n  string' }

Second run: crash with error:

   💾    ❨JSDB❩ Loading table table…
   💾    ❨JSDB❩  ╰─ Loading table synchronously.
undefined:1
_ = { 's': `a
             

SyntaxError: Unexpected end of input
    at JSTable.load (file:///home/aral/sandbox/jsdb-multiline-text-test/node_modules/@small-tech/jsdb/lib/JSTable.js:164:12)
    at new JSTable (file:///home/aral/sandbox/jsdb-multiline-text-test/node_modules/@small-tech/jsdb/lib/JSTable.js:57:12)
    at file:///home/aral/sandbox/jsdb-multiline-text-test/node_modules/@small-tech/jsdb/lib/JSDB.js:112:30
    at Array.forEach (<anonymous>)
    at JSDB.loadTables (file:///home/aral/sandbox/jsdb-multiline-text-test/node_modules/@small-tech/jsdb/lib/JSDB.js:109:61)
    at new JSDB (file:///home/aral/sandbox/jsdb-multiline-text-test/node_modules/@small-tech/jsdb/lib/JSDB.js:82:12)
    at Function.open (file:///home/aral/sandbox/jsdb-multiline-text-test/node_modules/@small-tech/jsdb/lib/JSDB.js:43:38)
    at file:///home/aral/sandbox/jsdb-multiline-text-test/index.js:3:19
    at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant