philippta / flyscrape

Flyscrape is a command-line web scraping tool designed for those without advanced programming skills.
https://flyscrape.com
Mozilla Public License 2.0
1.02k stars 29 forks source link

`NaN` quietly breaks all data #17

Closed remy closed 9 months ago

remy commented 9 months ago

I've just found that if I return NaN (unwittingly), it causes the entire response to become empty.

I've not looked at the Go source (and though I can probably read it, I've not programmed anything in anger with Go, so don't entirely trust myself), but my guess would be that the conversion is quietly failing and causes all data to be ejected.

Here's how to replicate in a script.mjs:

export const config = {
  url: 'https://example.com',
};

export default function () {
  return Array.from({ length: 10 }).map(() => ({
    a: 'test',
    b: NaN,
  }));
}

Result:

$ flyscrape run script.mjs
[

]

If I wrap the return value in a serialise/deserialise then it works again (but only because NaN gets mapped to null).

philippta commented 9 months ago

Thanks for reporting. The issue got fixed in #21 by running the return value through the JavaScript serialise/deserialise.

philippta commented 9 months ago

(but only because NaN gets mapped to null).

To give a bit more context: