Skip to content

Commit 95fa2d0

Browse files
committed
Handle empty string in profile change
1 parent 4bb9c4f commit 95fa2d0

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

auth/integration_test/src/integration_test.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -689,21 +689,22 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfileNull) {
689689
user = auth_->current_user();
690690
EXPECT_EQ(user.display_name(), kDisplayName);
691691
EXPECT_EQ(user.photo_url(), kPhotoUrl);
692+
// Setting the entries to null should leave the old values
692693
firebase::auth::User::UserProfile user_profile_null;
693-
user_profile_null.display_name = kDisplayName;
694+
user_profile_null.display_name = nullptr;
694695
user_profile_null.photo_url = nullptr;
695696
firebase::Future<void> update_profile_null = user.UpdateUserProfile(user_profile_null);
696697
WaitForCompletion(update_profile_null, "UpdateUserProfileNull");
697698
user = auth_->current_user();
698699
EXPECT_EQ(user.display_name(), kDisplayName);
699-
EXPECT_EQ(user.photo_url(), "");
700+
EXPECT_EQ(user.photo_url(), kPhotoUrl);
700701
SignOut();
701702
WaitForCompletion(
702703
auth_->SignInWithEmailAndPassword(email.c_str(), kTestPassword),
703704
"SignInWithEmailAndPassword");
704705
user = auth_->current_user();
705706
EXPECT_EQ(user.display_name(), kDisplayName);
706-
EXPECT_EQ(user.photo_url(), "");
707+
EXPECT_EQ(user.photo_url(), kPhotoUrl);
707708
DeleteUser();
708709
}
709710

@@ -725,20 +726,21 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfileEmpty) {
725726
user = auth_->current_user();
726727
EXPECT_EQ(user.display_name(), kDisplayName);
727728
EXPECT_EQ(user.photo_url(), kPhotoUrl);
728-
firebase::auth::User::UserProfile user_profile_null;
729-
user_profile_null.display_name = kDisplayName;
730-
user_profile_null.photo_url = "";
731-
firebase::Future<void> update_profile_null = user.UpdateUserProfile(user_profile_null);
732-
WaitForCompletion(update_profile_null, "UpdateUserProfileEmpty");
729+
// Setting the fields to empty should clear it.
730+
firebase::auth::User::UserProfile user_profile_empty;
731+
user_profile_empty.display_name = "";
732+
user_profile_empty.photo_url = "";
733+
firebase::Future<void> update_profile_empty = user.UpdateUserProfile(user_profile_empty);
734+
WaitForCompletion(update_profile_empty, "UpdateUserProfileEmpty");
733735
user = auth_->current_user();
734-
EXPECT_EQ(user.display_name(), kDisplayName);
736+
EXPECT_EQ(user.display_name(), "");
735737
EXPECT_EQ(user.photo_url(), "");
736738
SignOut();
737739
WaitForCompletion(
738740
auth_->SignInWithEmailAndPassword(email.c_str(), kTestPassword),
739741
"SignInWithEmailAndPassword");
740742
user = auth_->current_user();
741-
EXPECT_EQ(user.display_name(), kDisplayName);
743+
EXPECT_EQ(user.display_name(), "");
742744
EXPECT_EQ(user.photo_url(), "");
743745
DeleteUser();
744746
}

auth/src/android/user_android.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ Future<void> User::UpdateUserProfile(const UserProfile& profile) {
425425

426426
// Extra painfully call UserProfileChangeRequest.Builder.setPhotoUri.
427427
if (error == kAuthErrorNone && profile.photo_url != nullptr) {
428-
jobject j_uri = CharsToJniUri(env, profile.photo_url);
428+
jobject j_uri = nullptr;
429+
if (strlen(profile.photo_url) > 0) {
430+
j_uri = CharsToJniUri(env, profile.photo_url);
431+
}
429432
jobject j_builder_discard = env->CallObjectMethod(
430433
j_user_profile_builder,
431434
userprofilebuilder::GetMethodId(userprofilebuilder::kSetPhotoUri),
@@ -434,7 +437,9 @@ Future<void> User::UpdateUserProfile(const UserProfile& profile) {
434437
if (j_builder_discard) {
435438
env->DeleteLocalRef(j_builder_discard);
436439
}
437-
env->DeleteLocalRef(j_uri);
440+
if (j_uri) {
441+
env->DeleteLocalRef(j_uri);
442+
}
438443
}
439444

440445
jobject j_user_profile_request = nullptr;

0 commit comments

Comments
 (0)