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;
if (voiceVerification) {
response = accountManager.requestVoiceVerificationCode(Utils.getDefaultLocale(),
response = accountManager.requestVoiceVerificationCode(Utils.getDefaultLocale(null),
Optional.fromNullable(captcha),
Optional.absent(),
Optional.absent());

View file

@ -30,6 +30,7 @@ import java.nio.file.Files;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
@ -199,7 +200,7 @@ public final class ProfileHelper {
}
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);
}
@ -319,7 +320,7 @@ public final class ProfileHelper {
SignalServiceProfile.RequestType requestType
) {
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 -> {
var processor = new ProfileService.ProfileResponseProcessor(pair);

View file

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