[SERVER-7424] Shell trims multiple whitespace characters in strings when displaying (data not affected) Created: 19/Oct/12 Updated: 11/Jul/16 Resolved: 11/Mar/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 2.0.7, 2.2.0 |
| Fix Version/s: | 2.4.4, 2.5.0 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Adam Comerford | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Tested on Linux - 2.2.0 and 2.0.7 |
||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Minor Change | ||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
The shell trims whitespace when displaying find results, but the data is correctly inserted and can be queried appropriately: From here: http://dba.stackexchange.com/questions/27200/preserving-whitespace-in-mongodb-values Quick test to show it happening:
|
| Comments |
| Comment by auto [ 13/May/13 ] | ||||||||||||||||||||||||||||||||||||
|
Author: {u'date': u'2013-03-11T12:35:26Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: When displaying small objects, convert only tabs, carriage returns and | ||||||||||||||||||||||||||||||||||||
| Comment by auto [ 11/Mar/13 ] | ||||||||||||||||||||||||||||||||||||
|
Author: {u'date': u'2013-03-11T12:35:26Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: When displaying small objects, convert only tabs, carriage returns and | ||||||||||||||||||||||||||||||||||||
| Comment by Tad Marshall [ 11/Mar/13 ] | ||||||||||||||||||||||||||||||||||||
|
The code is trying to make things print "nicely" when formatting has not been explicitly set and when the output can fit on one line (before processing, hmmm ...). It compresses every block of whitespace to a single space. This is probably helpful for whitespace between fields, but it isn't selective and it smushes whitespace in string fields to a single space. src/mongo/shell/types.js lines 539 to 545 (in tojson()):
If you add text to the object to push its unprocessed length to 80 or more characters, it goes multi-line and you see the spaces:
You don't need to store and fetch a document to reproduce this, you can just create a local object in the shell. The regular expression is doing too much. The tojsonObject() function inserts tabs and newlines and doesn't add multiple spaces or carriage returns, so stripping just tabs and newlines gives the more concise display without hammering spaces in strings. Tabs and newlines in strings should already have been escaped to backslash-t and backslash-n, so stripping them should not hurt anything.
| ||||||||||||||||||||||||||||||||||||
| Comment by Tad Marshall [ 19/Oct/12 ] | ||||||||||||||||||||||||||||||||||||
|
Yes, something funny in the display code:
|