1 Reply Latest reply on Nov 24, 2015 12:39 AM by matias.kiviniemi

    Different Javascript execution in ESTK and Node.js

    matias.kiviniemi Level 3

      I have this function for sanitizing text for JSON output that simplifies different line feed formats and escapes the quotation marks. So far it has worked fine, but now I noticed that when ESTK and Node.js provide different output when executed with a line change:

      • ESTK outputs "\n"
      • Node.js outputs "\\n"


      I.e. the string literal gets different treatment, but not sure if that's the Javascript parsing or .replace itself. Thoughts, Ideas?

       

      sanitizeJsonText: function(str) {

        return str.replace(/\r\n/g, "\\n")

        .replace(/\r/g, "\\n")

        .replace(/\n/g, "\\n")

        .replace(/\'/g, "\\'")

        .replace(/\"/g, "\\\"");

      },