mongodb / mongodb/support-tools
getMongoData.js – Wrong handling of strings that look like dates
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 140
- Forks
- 154
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 2
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in getMongoData.js at jsonStringifyReplacer and inspect how ISODate values reach the replacer, including whether any related tests or callers exist. Reproduce the conversion with an arbitrary alphanumeric string and an actual date; done means ordinary strings remain unchanged while intended date values retain the expected output representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100