Fix findExistingAccount to treat underscore properly

Bug: 2318959
Change-Id: Ia39ed29084dc8111c61ff552fa65519789b7c23a
This commit is contained in:
Marc Blank 2011-10-20 17:40:33 -07:00
parent d6d3a4929d
commit 0ff0e155c5
2 changed files with 14 additions and 3 deletions

View File

@ -279,7 +279,7 @@ public class Utility {
}
}
private final static String HOSTAUTH_WHERE_CREDENTIALS = HostAuthColumns.ADDRESS + " like ?"
+ " and " + HostAuthColumns.LOGIN + " like ?"
+ " and " + HostAuthColumns.LOGIN + " like ? ESCAPE '\\'"
+ " and " + HostAuthColumns.PROTOCOL + " not like \"smtp\"";
private final static String ACCOUNT_WHERE_HOSTAUTH = AccountColumns.HOST_AUTH_KEY_RECV + "=?";
@ -295,8 +295,9 @@ public class Utility {
public static Account findExistingAccount(Context context, long allowAccountId,
String hostName, String userLogin) {
ContentResolver resolver = context.getContentResolver();
String userName = userLogin.replace("_", "\\_");
Cursor c = resolver.query(HostAuth.CONTENT_URI, HostAuth.ID_PROJECTION,
HOSTAUTH_WHERE_CREDENTIALS, new String[] { hostName, userLogin }, null);
HOSTAUTH_WHERE_CREDENTIALS, new String[] { hostName, userName }, null);
if (c == null) throw new ProviderUnavailableException();
try {
while (c.moveToNext()) {

View File

@ -39,7 +39,7 @@ import java.io.IOException;
* complete - no server(s) required.
*
* You can run this entire test case with:
* runtest -c com.android.email.UtilityMediumTests email
* runtest -c com.android.emailcommon.utility.UtilityMediumTests email
*/
@MediumTest
public class UtilityMediumTests extends ProviderTestCase2<EmailProvider> {
@ -80,6 +80,16 @@ public class UtilityMediumTests extends ProviderTestCase2<EmailProvider> {
// Try to find account1, excluding account1
acct = Utility.findExistingAccount(mMockContext, account1.mId, "address-ha1", "login-ha1");
assertNull(acct);
// Make sure we properly handle an underscore in the login name
Account account3 = ProviderTestUtils.setupAccount("account3", false, mMockContext);
account3.mHostAuthRecv = ProviderTestUtils.setupHostAuth("foo_ba", -1, false, mMockContext);
account3.mHostAuthSend = ProviderTestUtils.setupHostAuth("foo_ba", -1, false, mMockContext);
account3.save(mMockContext);
acct = Utility.findExistingAccount(mMockContext, -1, "address-foo_ba", "login-foo.ba");
assertNull(acct);
acct = Utility.findExistingAccount(mMockContext, -1, "address-foo_ba", "login-foo_ba");
assertNotNull(acct);
}
public void testAttachmentExists() throws IOException {