unjs / rc9

Read/Write config couldn't be easier!
Other
269 stars 5 forks source link

Error on empty values #119

Closed thezzisu closed 3 months ago

thezzisu commented 4 months ago

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

thezzisu commented 4 months ago

The reason is just simple: at

https://github.com/unjs/rc9/blob/ca463063ade9953c845b694d25a88e91e0b214dc/src/index.ts#L53

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

pi0 commented 3 months ago

It should be fixed in next release