unjs/rc9

Error on empty values

thezzisu opened this issue · 2 comments

Environment

Package: v2.1.1
Node: v20.10.0

Reproduction

> rc9-poc cat .conf
a=
> rc9-poc node -e "require('rc9').read()"
/home/thezzisu/Workspace/rc9-poc/node_modules/rc9/dist/index.cjs:41
      match[2].trim()
               ^

TypeError: Cannot read properties of undefined (reading 'trim')
    at parse (/home/thezzisu/Workspace/rc9-poc/node_modules/rc9/dist/index.cjs:41:16)
    at parseFile (/home/thezzisu/Workspace/rc9-poc/node_modules/rc9/dist/index.cjs:57:10)
    at Object.read (/home/thezzisu/Workspace/rc9-poc/node_modules/rc9/dist/index.cjs:61:10)
    at [eval]:1:16
    at runScriptInThisContext (node:internal/vm:144:10)
    at node:internal/process/execution:109:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:92:62)
    at evalScript (node:internal/process/execution:123:10)
    at node:internal/main/eval_string:51:3

Node.js v20.10.0

Describe the bug

When config file have a KV-pair with a empty value, an error will be thrown which is not expected and will crash the app

Additional context

No response

Logs

No response

The reason is just simple: at

const value = destr(match[2].trim() /* val */);

When the value is empty match[2] is undefined. I will soon write a fix for that.

pi0 commented

It should be fixed in next release