[SERVER-4431] mongo shell doesn't escape characters in strings correctly Created: 05/Dec/11 Updated: 09/Oct/16 Resolved: 22/Jul/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Pasette (Inactive) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
mongo shell running under cygwin, although that shouldn't affect this |
||
| Issue Links: |
|
||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||
| Operating System: | ALL | ||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
Tried the following in the mongo shell > use foo ); ); > The handling of backslashes within strings does not seem to be consistent. The first example removes some of them without doing anything to the following characters. The second example fails to use " |
| Comments |
| Comment by William Zola [ 03/Jul/12 ] | ||||||||||
|
The issue is that the mongo shell helpfully re-quotes any string which contains backslashes when it prints it out. The data stored in MongoDB doesn't really have the double-backslashes, it's just printed that way.
| ||||||||||
| Comment by Jeff Ozvold [ 05/Dec/11 ] | ||||||||||
|
The behavior appears to be sane to me. In the first example, I would expect unrecognized escape sequences to be converted to the normal characters, such as '\a' to 'a'. . I would then expect 'a' to be returned to the shell as 'a'. With recognized escape sequences, like double-backslashes and '\b', I would expect JS to convert them to the normal character, as in double-backslashes to '\' and '\b' to backspace. Then, when displaying them, reconvert them back in to the corresponding escape sequences. In the Mozilla Reference https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#String_Literals is the phrase: Also, if you just do normal JS vars, you get this output:
|