Javascript eval json with base64 encoded fields

I use sun.misc.BASE64Encoder to encode an encrypted value, which is then added to the JSON field and then sent to the client. I am using Javascript eval () on the client to create an object from JSON code. When eval () starts, it gives an error:

unterminated string literal

There are other fields in the JSON code, but I narrowed down the error specifically for the base64 encoded field. Here is an abusive line of javascript code:

var result = eval( '(' + xhr.responseText + ')' ); 

Here is the JSON object from the servlet:

{
  'resource':'resource?Signature=j79r/2Hly+HqhS/6fdd+prfsR+kUNijUvDN0QJ14ZR43gzYScOMDypt/crks/CEphTUXVptJvSol
1ZOOvScCUhNOCb7dZk/3MKnI5tOewSACXK32/OJNd8hYpZtSTn+WhA6+f9BUIUZWA83U8Cud/Tb8V
R1yQWbDGG/mM/NiUSiY=', 

'url':'http://somesite.com/pr'
}

I'm not sure why eval is dying, but it looks like the value of the JSON "resource" field contains what it doesn't need.

Thanks in advance. Tim

+3
source share
1 answer

, , JSON, , . , ?

+1

Source: https://habr.com/ru/post/1752013/


All Articles