Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-398

Having leading comments in Javascript can break db.eval()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.1.4
    • Affects Version/s: None
    • Component/s: JavaScript
    • None

      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

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            eliot Eliot Horowitz (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: