[SERVER-3470] multiline commands are not saved completly in history Created: 23/Jul/11 Updated: 12/Jul/16 Resolved: 18/Nov/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 1.9.1 |
| Fix Version/s: | 2.1.0 |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Swapnil Tailor | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 0 |
| Labels: | commands, history, rn | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu 11.04 i386 |
||
| Issue Links: |
|
||||
| Participants: | |||||
| Description |
|
While entering multi-line command, mongodb shell persist only first line of the command in history. It should persist multiple line of the command as a whole like MySql does. For example: when i type as below: Ideally it should save the whole command and next time when i check history it should bring back the command as a whole. Fix: Changing this line will start storing the whole command in history. But not sure from where the command is read again so that piece also need to take care of this scenario. line:788 shellHistoryAdd( line ); ==> shellHistoryAdd(code.c_str() ); |
| Comments |
| Comment by Tad Marshall [ 18/Nov/11 ] |
|
Fixed in commit 05717037fb8cf7b8bf9f7e935d23e64f74a70311. |
| Comment by auto [ 18/Nov/11 ] |
|
Author: {u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: Convert newlines to spaces and store the entire multi-line command instead |
| Comment by Eliot Horowitz (Inactive) [ 15/Oct/11 ] |
|
I'm not sure that's exactly the behavior we want. I can see the value in this, just not sure which people expect. |
| Comment by Tad Marshall [ 13/Oct/11 ] |
|
One more time ... I closed pull request 118 and opened https://github.com/mongodb/mongo/pull/119 to replace it. |
| Comment by Tad Marshall [ 13/Oct/11 ] |
|
I closed pull request 102 and opened https://github.com/mongodb/mongo/pull/118 to replace it. |
| Comment by Eliot Horowitz (Inactive) [ 10/Oct/11 ] |
|
need to read pull 102 more |
| Comment by Tad Marshall [ 07/Oct/11 ] |
|
Hi Swapnil, An additional comment on the error you were hitting ... I'm not sure why the error that is showing up in your earlier comment is "unterminated string literal" and this seems like an odd message when you didn't include a string literal. But the "big picture" nature of the error is that when you enter a multiline command, there is code that runs that works on what you typed and prepares it for passing to the JavaScript interpreter. When a command line is recalled, none of this code runs, and your text is passed directly to the command line handler which (in this case) passes it off to the JavaScript interpreter without the extra processing. The newline in the text that is passed is somehow being interpreted such that the "unterminated string literal" error is what it hits, and this kind of thing could change as we transition from one JavaScript engine to another. It could also be an artifact of our internal processing of your input (suggested by the "(shellhelp1):1" portion of the error message). But the "bottom line" is that passing newlines directly to this code doesn't work, and converting the newlines to spaces does work except for the automatic semicolon insertion issue I mentioned above. Since your fix works (with the newline change) and is a real improvement, I suspect that you'll see it in a future release. Thanks for the thanks. Bug reports are at their best when we're provided the code changes. Thanks for your support! Tad |
| Comment by Swapnil Tailor [ 07/Oct/11 ] |
|
Thanks Tad for including the changes into your pull request. |
| Comment by Tad Marshall [ 07/Oct/11 ] |
|
One additional thing to note is that the recalled command may need to have semicolons inserted into it to work right when you hit return to enter it. JavaScript has a concept of "automatic semicolon insertion": see section 7.9 in the ECMAScript standard (an online copy is at http://bclary.com/2004/11/07/#a-7.9 ). Because of this, converting newlines to spaces can break legal JavaScript if the code was relying on this feature. This isn't a big deal because you can either include semicolons at the end of lines where JavaScript would insert them automatically, or you can add them with command line editing before you hit return. |
| Comment by Tad Marshall [ 07/Oct/11 ] |
|
Hi Swapnil, The reason you are getting this error is that code.c_str() includes all the newline characters from your multiline command. I issued my own pull request to get your fix in with the addition of converting newlines to spaces. It works great, thanks for suggesting this and showing us the fix! Your db.help example works now and history brings back db.help( ) which is the full command with the newline converted to a space. See https://github.com/mongodb/mongo/pull/102 for the code changes. Tad |
| Comment by Swapnil Tailor [ 26/Jul/11 ] |
|
Hi Eliot, Made the changes for the same. |
| Comment by Swapnil Tailor [ 24/Jul/11 ] |
|
after making above suggested changes, i am facing below error when i immediately execute the same command after taking it from history. Not sure why sytnax error is coming while executing the same command after fetching it from history and executing it. Any idea? In both the case i checked the ascii characters and they were both same as below: |