[SERVER-27997] mongo connection URI cannot connect when there's "@" character in password Created: 14/Feb/17 Updated: 31/May/17 Resolved: 16/Feb/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | tracy | Assignee: | Spencer Jackson |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
There is a "@" character in my password and I tried to use connection string URI to connect MongoDB mongo 'mongodb://user:abc@123@localhost:27017' And I get this error: ~➜ ~ mongo 'mongodb://da:abc@123@localhost:27017' But mongo admin -u da -p 'abc@123' works well.So I read the mongo shell and mongo-cxx-driver code and I found this: ~namespace { const char kMongoDBURL[] = // scheme: non-capturing "mongodb://" // credentials: two inner captures for user and password "(?:([^:]+)(?::([^@]+))?@)?" // servers: grabs all host:port or UNIX socket names "((?:(?:[^\\/]+|/.+.sock?),?)+)" // database: matches anything but the chars that cannot // be part of a MongoDB database name. "(?:/([^/\\.\\ \"*<>:\\|\\?]*))?" // options "(?:\\?(?:(.+=.+)&?)+)*"; }// namespace~ So it means that if my connection URI is mongo 'mongodb://user:abc@123@localhost:27017' it will return mongodb://da1:abc@ rather than mongodb://da1:abc@123@ ,is it a bug or I missed something? Thanks. |
| Comments |
| Comment by Spencer Jackson [ 16/Feb/17 ] |
|
Hi! You are correct, and this isn't something you can do right now in a connection URI. In general, it's not possible to stick an '@' there given the URI format, so you're supposed to percent encode the '@' into '%40'. Unfortunately, the shell doesn't currently support percent encoding. |