fix from https://github.com/n1k0/casperjs/pull/432/files