[SERVER-398] Having leading comments in Javascript can break db.eval() Created: 30/Oct/09  Updated: 12/Jul/16  Resolved: 10/Nov/09

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 1.1.4

Type: Bug Priority: Minor - P4
Reporter: Eliot Horowitz (Inactive) Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

This works:

> db.eval(/dieinafire/function()

{return [true];})
[true]

As does this:

> db.eval("function(){return [true];}

")
[true]

Starting with a string with a comment does not:

> db.eval("/dieinafire/function()

{return [true];}

")
null

mstearn in #mongodb said:

< mstearn> yup, function literal vs sting with function

So I guess this is a known behavior. However, it's completely non-
obvious when you run into it via a client library.

Is there a way to db.eval() javascript code that starts with a comment
via pymongo?

Obviously for now I've just removed the comment, but I wasted an
afternoon trying to figure out why in the world some perfectly valid
Javascript wasn't executing.

Thanks,
schmichael



 Comments   
Comment by auto [ 10/Nov/09 ]

Author:

{'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: handle comments at the beginning of code SERVER-398
http://github.com/mongodb/mongo/commit/8af511ef9b8fab64893960b776b3682de6fb7932

Comment by Michael Schurter [ 02/Nov/09 ]

Wrapping my code in a pymongo.code.Code() object allows me to start with a comment. Perhaps a leading comment only breaks the data_code BSON type and not the data_code_w_scope type?

Generated at Thu Feb 08 02:53:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.