ariya / phantomjs

Scriptable Headless Browser

Home Page:http://phantomjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

page.evaluate returns empty string when parsing null values

calvin-git opened this issue · comments

hi,

i'm working with casperJS but i think the issue comes from phantomjs, that's why i post here. It seems that null values in json results are not properly handled by the evaluate method : with the following sample test:

var casper = require('casper').create();
casper.start("http://www.google.com/");
var res = (
casper.evaluate(
function() { return {foo: null}; }
)
);
console.log(JSON.stringify(res));

the output is {foo: ""} instead of {foo:null}. I have to use the following workaround to get the correct output:

var casper = require('casper').create();
casper.start("http://www.google.com/");
var res = (
casper.evaluate(
function() { return "res:" + JSON.stringify({foo: null}); }
)
);
console.log(JSON.stringify(JSON.parse(res.substring(4))));

it seems that evaluate does an implicit stringify on the client side followed by an implicit parse on the server side, but those calls mess up null values. I read the documentation about evaluate but didn't found any hint about why such behaviour or means to override it

while the workaround is doing what i need, it seems like a performance waste and it would be better to directly have null values in my first test case. Can someone provide some informations on this issue ?

thanks a lot

Also reproduceable with the simplest example:

var webpage = require('webpage');
var page = webpage.create();
var result = page.evaluate(function() {
    return { foo: 2 };
});
console.log('result is', JSON.stringify(result));
commented

Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!