Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMongoData.js – Wrong handling of strings that look like dates #47

Open
drmirror opened this issue Nov 3, 2016 · 0 comments
Open

Comments

@drmirror
Copy link

drmirror commented Nov 3, 2016

In getMongoData.js, any string that is parseable as an ISODate is converted into { $date : ... } in the output. This is wrong, I am in fact seeing fields that contain arbitrary alphanumeric codes being converted into $date notation. This is apparently done by this section in the code:

// For use in JSON.stringify to properly serialize known types
function jsonStringifyReplacer(k, v){
    if (v instanceof ObjectId)
        return { "$oid" : v.valueOf() };
    if (v instanceof NumberLong)
        return { "$numberLong" : longmangle(v) };
    if (v instanceof NumberInt)
        return v.toNumber();
    // For ISODates; the $ check prevents recursion
    if (typeof v === "string" && k.startsWith('$') == false){
        try {
            iso = ISODate(v);
            return { "$date" : iso.valueOf() };
        }
        // Nothing to do here, we'll get the return at the end
        catch(e) {}
    }
    return v;
}

Actually, I don't think it's right to parse strings into ISODates at all here, but I don't understand the overall logic well enough. Intuitively, I would think that v instanceof ISODate should suffice here.

@drmirror drmirror changed the title Wrong handling of strings that look like dates getMongoData.js – Wrong handling of strings that look like dates Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant