bug in utils.stringReplace if replace param is null

Hello,

the following code

var test = 'abcdef';
var java = test.replace('ab',null);
var util = utils.stringReplace(test, 'ab', null);
application.output('result java: ' + java);
application.output('result util: ' + util);

results in

result java: cdef
result util:

This shouldn’t be! If null is provided, it should be treated as an empty string. I frequently use this for example looping over a record’s column. If one of the columns is null, my string is empty!

Thanks
Patrick

I second this notion.

So far I’ve had to use a special wrapper method for utils.stringReplace that checks for a null argument and replaces it with an empty string to get around this; but it would be nice to not have to.

So, if I understand that you want a null value to be treated (or converted into) as “”. If that’s the case I don’t agree.

The two are really different things.
And, although the idea of not having to evaluate is appealing.
And, although I also don’t need to differ between the two very often, they are different…

Certainly in an Array this behaviour is very good…

Marcel’s right, actually. Coming from the FileMaker world, I was insulated from worrying about NULL, but that’s not the case now :wink: FWIW, it helps me to think of NULL as “unknown”, so replacing “ab” in the example above with an unknown value should return NULL.

Having said that, I find it a little strange that an expression like (1 + NULL) equals 1 in JavaScript. I would expect NULL, because how can you add an unknown value and get a known value? The same thing happens with the expression (NULL + “Servoy”). It’s “Servoy”, not NULL.

OK, my post was arguably DULL :)