[JAVA-449] MongoURI parsing does not handle escaping Created: 14/Oct/11  Updated: 06/Apr/23  Resolved: 13/Mar/14

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.6.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Caleb Jones Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Repro steps:

JUnit Test Snippet

@Test
public void testMultipleAts() {
   MongoURI uri = new MongoURI("mongodb://usernme:p@ssword@localhost:27017/test");
   assertEquals("p@ssword", uri.getPassword()); // <-- FAILS
 
   // this behavior might be expected behavior as '@' should be URI-escaped
   // however maybe a parse error should be thrown since at this point:
   //   * uri.getHosts() == ["ssword@localhost:27017"]
   //   * uri.getPassword() == ['p']
}
 
@Test
public void testUriEscaping() {
   MongoURI uri = new MongoURI("mongodb://usernme:p%40ssword@localhost:27017/test");
   assertEquals("p@ssword", uri.getPassword()); // <-- FAILS and shouldn't
 
   // at this point uri.getPassword() == ['p', '%', '4', '0', 's', 's', 'w', 'o', 'r', 'd']
   // which is wrong
}

Expected:

  • MongoURI should support URI escaping.

Actual:

  • No URI escaping/unescaping is handled in MongoURI


 Comments   
Comment by Jeffrey Yemin [ 13/Mar/14 ]

I tried this with the most recent driver and it works as expected, with one change: the second test needs to be fixed to compare strings instead of a string and a char array.

Comment by Caleb Jones [ 14/Oct/11 ]

Note, example just involves '@' but larger issue is URI escaping in general (which involves many more characters than just '@').

Generated at Thu Feb 08 08:52:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.