Fix profile fetch with an invalid LANG variable

This commit is contained in:
AsamK 2022-01-17 18:26:08 +01:00
parent 4310059e6a
commit 7d935749aa
3 changed files with 7 additions and 6 deletions

View file

@ -131,7 +131,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
} }
final ServiceResponse<RequestVerificationCodeResponse> response; final ServiceResponse<RequestVerificationCodeResponse> response;
if (voiceVerification) { if (voiceVerification) {
response = accountManager.requestVoiceVerificationCode(Utils.getDefaultLocale(), response = accountManager.requestVoiceVerificationCode(Utils.getDefaultLocale(null),
Optional.fromNullable(captcha), Optional.fromNullable(captcha),
Optional.absent(), Optional.absent(),
Optional.absent()); Optional.absent());

View file

@ -30,6 +30,7 @@ import java.nio.file.Files;
import java.util.Base64; import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -199,7 +200,7 @@ public final class ProfileHelper {
} }
private SignalServiceProfile retrieveProfileSync(String username) throws IOException { private SignalServiceProfile retrieveProfileSync(String username) throws IOException {
final var locale = Utils.getDefaultLocale(); final var locale = Utils.getDefaultLocale(Locale.US);
return dependencies.getMessageReceiver().retrieveProfileByUsername(username, Optional.absent(), locale); return dependencies.getMessageReceiver().retrieveProfileByUsername(username, Optional.absent(), locale);
} }
@ -319,7 +320,7 @@ public final class ProfileHelper {
SignalServiceProfile.RequestType requestType SignalServiceProfile.RequestType requestType
) { ) {
final var profileService = dependencies.getProfileService(); final var profileService = dependencies.getProfileService();
final var locale = Utils.getDefaultLocale(); final var locale = Utils.getDefaultLocale(Locale.US);
return profileService.getProfile(address, profileKey, unidentifiedAccess, requestType, locale).map(pair -> { return profileService.getProfile(address, profileKey, unidentifiedAccess, requestType, locale).map(pair -> {
var processor = new ProfileService.ProfileResponseProcessor(pair); var processor = new ProfileService.ProfileResponseProcessor(pair);

View file

@ -84,16 +84,16 @@ public class Utils {
theirIdentityKey); theirIdentityKey);
} }
public static Locale getDefaultLocale() { public static Locale getDefaultLocale(Locale fallback) {
final var locale = Locale.getDefault(); final var locale = Locale.getDefault();
if (locale == null) { if (locale == null) {
return null; return fallback;
} }
try { try {
Locale.LanguageRange.parse(locale.getLanguage() + "-" + locale.getCountry()); Locale.LanguageRange.parse(locale.getLanguage() + "-" + locale.getCountry());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.debug("Invalid locale, ignoring: {}", locale); logger.debug("Invalid locale, ignoring: {}", locale);
return null; return fallback;
} }
return locale; return locale;