Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

page.evaluate returns empty string when parsing null values #11268

Closed
calvin-git opened this issue Apr 25, 2013 · 2 comments
Closed

page.evaluate returns empty string when parsing null values #11268

calvin-git opened this issue Apr 25, 2013 · 2 comments
Labels

Comments

@calvin-git
Copy link

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

@ariya
Copy link
Owner

ariya commented Nov 24, 2013

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));

@ghost ghost removed old.Module-WebPage labels Dec 19, 2017
@stale stale bot added the stale label Dec 26, 2019
@stale
Copy link

stale bot commented Dec 29, 2019

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!

@stale stale bot closed this as completed Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants