1

I have a mpgw where the request is JSON. I save the content in a context variable with JSON.stringify(json) The problem is when json contains a emoiji eg \uD83D\uDE0D tha variable no longer will be a string, it will be binary and the emoijis is shown as dots. I need to use the the content of the variable later to calculate hmac so it has to look exact as the original json.

Is there any way to get around this? Help wold be much appreciated.

We are running firmware: IDG.7.5.2.9

/Jocke D

JockeD
  • 11
  • 2
  • Could you elaborate on how you store the String into the context variable? Maybe the code or Action used? – Anders Nov 02 '17 at 06:23
  • I read the input with: session.input.readAsJSON(function (error, json) and then store the data with: ctx.setVar('json', JSON.stringify(json)); – JockeD Nov 03 '17 at 07:28

1 Answers1

0

Ok, from your comment I can conclude that it is the Stringify() that messes it up. This is according to the cookbook for escaping (there is a RFC describing this)...

Try adding your own function for stringify() that will handle unicode better:

function JSON_stringify(s, emit_unicode) {
   var json = JSON.stringify(s);
   return emit_unicode ? json : json.replace(/[\u007f-\uffff]/g,
      function(c) { 
        return '\\u'+('0000'+c.charCodeAt(0).toString(16)).slice(-4);
      }
   );
}

ctx.setVar('json', JSON_stringify(json, false));

Something like that...

Anders
  • 3,198
  • 1
  • 20
  • 43