mishrsud / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

script error on parse json dates if already handled #77

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.have a generic handler to 'fix' json date serialization - see below
2.get a script error on line 365 of mini-profiler-includes.js in renderDate 
function
3.should check that typeof jsonDate === 'string' before trying to parse it

the replacement function for handling json dates is:
(function() {
   var _origParse = JSON.parse;

   JSON.parse = function(text) {
      return _origParse(text, function(key, value) {
         var a;

         if (typeof value === 'string') {
            a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
 //UTC
            if (a)
                 return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));
 //msajax
            if (value.slice(0, 6) === '/Date(' && value.slice(-2) === ')/') {
               var d = new Date(parseInt(value.slice(6, -2),10));

               if (d)
                  return d;
            }
         }

         return value;
      });
   }
})();

Original issue reported on code.google.com by stevebak...@gmail.com on 28 Jul 2011 at 3:34

GoogleCodeExporter commented 8 years ago
This will now be handled correctly (given the formats Microsoft chose here, 
global parsing is an expected thing to encounter).

You can see the related changeset here: 
http://code.google.com/p/mvc-mini-profiler/source/detail?r=28d15f4bcc98c725d6903
40662851c32d2c2ffd5

Original comment by nrcraver on 16 Aug 2011 at 11:18