Make toUpperCase conversions locale invariant

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190942033
This commit is contained in:
olly 2018-03-29 09:38:54 -07:00 committed by Oliver Woodman
parent 1648e4e9f9
commit 3a98f7aa99
3 changed files with 14 additions and 4 deletions

View File

@ -200,7 +200,7 @@ public final class MimeTypes {
String objectTypeString = codec.substring(5); // remove the 'mp4a.' prefix String objectTypeString = codec.substring(5); // remove the 'mp4a.' prefix
if (objectTypeString.length() >= 2) { if (objectTypeString.length() >= 2) {
try { try {
String objectTypeHexString = objectTypeString.toUpperCase().substring(0, 2); String objectTypeHexString = Util.toUpperInvariant(objectTypeString.substring(0, 2));
int objectTypeInt = Integer.parseInt(objectTypeHexString, 16); int objectTypeInt = Integer.parseInt(objectTypeHexString, 16);
mimeType = getMimeTypeFromMp4ObjectType(objectTypeInt); mimeType = getMimeTypeFromMp4ObjectType(objectTypeInt);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {

View File

@ -329,6 +329,16 @@ public final class Util {
return text == null ? null : text.toLowerCase(Locale.US); return text == null ? null : text.toLowerCase(Locale.US);
} }
/**
* Converts text to upper case using {@link Locale#US}.
*
* @param text The text to convert.
* @return The upper case text, or null if {@code text} is null.
*/
public static String toUpperInvariant(String text) {
return text == null ? null : text.toUpperCase(Locale.US);
}
/** /**
* Formats a string using {@link Locale#US}. * Formats a string using {@link Locale#US}.
* *

View File

@ -20,12 +20,12 @@ import static com.google.common.truth.Truth.assertThat;
import android.net.Uri; import android.net.Uri;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment; import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
import com.google.android.exoplayer2.util.Util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@ -122,7 +122,7 @@ public class HlsMediaPlaylistParserTest {
.isEqualTo("https://priv.example.com/key.php?r=2682"); .isEqualTo("https://priv.example.com/key.php?r=2682");
// 0xA7A == 2682. // 0xA7A == 2682.
assertThat(segment.encryptionIV).isNotNull(); assertThat(segment.encryptionIV).isNotNull();
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7A"); assertThat(Util.toUpperInvariant(segment.encryptionIV)).isEqualTo("A7A");
assertThat(segment.byterangeLength).isEqualTo(51740); assertThat(segment.byterangeLength).isEqualTo(51740);
assertThat(segment.byterangeOffset).isEqualTo(2147586650L); assertThat(segment.byterangeOffset).isEqualTo(2147586650L);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2682.ts"); assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2682.ts");
@ -134,7 +134,7 @@ public class HlsMediaPlaylistParserTest {
.isEqualTo("https://priv.example.com/key.php?r=2682"); .isEqualTo("https://priv.example.com/key.php?r=2682");
// 0xA7B == 2683. // 0xA7B == 2683.
assertThat(segment.encryptionIV).isNotNull(); assertThat(segment.encryptionIV).isNotNull();
assertThat(segment.encryptionIV.toUpperCase(Locale.getDefault())).isEqualTo("A7B"); assertThat(Util.toUpperInvariant(segment.encryptionIV)).isEqualTo("A7B");
assertThat(segment.byterangeLength).isEqualTo(C.LENGTH_UNSET); assertThat(segment.byterangeLength).isEqualTo(C.LENGTH_UNSET);
assertThat(segment.byterangeOffset).isEqualTo(0); assertThat(segment.byterangeOffset).isEqualTo(0);
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts"); assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");