zazuko / clownface

Simple but powerful graph traversing library for RDF
https://zazuko.github.io/clownface/
37 stars 8 forks source link

Empty strings are mapped to undefined #17

Closed tpluscode closed 5 years ago

tpluscode commented 5 years ago

When passing empty string to create a node with clownface, undefined is returned which causes hard to detect errors down the line.

The problem lies on this line: https://github.com/rdf-ext/clownface/blob/master/lib/term.js#L53-L55

I notice that the term is actually relying on how it handles null values and undefined as return value. Thus, I'd propose a change as follows so that empty string or zeros are not ignored.

-  if (!value) {
+  if (value === null || typeof value === 'undefined') {
bergos commented 5 years ago

Yes, that's a bug and it should be just like you described it in your diff. PR which includes a test for it is very welcome.