iotagent-node-lib icon indicating copy to clipboard operation
iotagent-node-lib copied to clipboard

replaceallstr and replaceallregexp JEXL transformations not working

Open fgalan opened this issue 3 years ago • 2 comments

We have the following functions JEXL transformations in lib/jexlTranformsMap.js

    replaceallstr: (str, from, to) => str.replaceAll(from, to),
    replaceallregexp: (str, reg, to) => str.replaceAll(new RegExp(reg, 'g'), to),

Both are using str.replaceAll()

However, according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibility str.replaceAll() is not supported in Nodejs until v15. Currently we have >=12 in packages.json (and v14 in Dockerfile).

We should check if they replaceallstr and replaceallregexp JEXL transformation are actually working. In negative case, I'd suggest to disable them commenting out in that file with a FIXME mark about it, to be re-enabled once we update node to v16.

fgalan avatar Jun 22 '22 08:06 fgalan

replaceAll is still working ini nodejs v16:

node Welcome to Node.js v16.16.0. Type ".help" for more information.

var a = "33" undefined a.replaceAll('3','c') 'cc'

const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?'; undefined

console.log(p.replaceAll('dog', 'monkey')); The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy? undefined // expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?" undefined

// global flag required when calling replaceAll with regex undefined const regex = /Dog/ig; undefined console.log(p.replaceAll(regex, 'ferret')); The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy? undefined // expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?" undefined

AlvaroVega avatar Jul 26 '22 07:07 AlvaroVega

replaceAll is still working ini nodejs v16:

Note we have >=12 in packages.json. Thus, if we upgrade to >=16 I think we could close this issue without any further action.

fgalan avatar Aug 02 '22 09:08 fgalan

Currently we are using nodejs 16 or upper: https://github.com/telefonicaid/iotagent-node-lib/blob/7b7c9506bec8db6a29ac8ef3a193e969f09334e6/package.json#L25-L27

so, can we close this issue @fgalan ?

AlvaroVega avatar Apr 20 '23 08:04 AlvaroVega