From 3a98f7aa9925c7b9cfa84bf261b786479b662369 Mon Sep 17 00:00:00 2001 From: olly Date: Thu, 29 Mar 2018 09:38:54 -0700 Subject: [PATCH] Make toUpperCase conversions locale invariant ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=190942033 --- .../com/google/android/exoplayer2/util/MimeTypes.java | 2 +- .../java/com/google/android/exoplayer2/util/Util.java | 10 ++++++++++ .../hls/playlist/HlsMediaPlaylistParserTest.java | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/MimeTypes.java b/library/core/src/main/java/com/google/android/exoplayer2/util/MimeTypes.java index 778ea9487b..041ee55cf1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/MimeTypes.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/MimeTypes.java @@ -200,7 +200,7 @@ public final class MimeTypes { String objectTypeString = codec.substring(5); // remove the 'mp4a.' prefix if (objectTypeString.length() >= 2) { try { - String objectTypeHexString = objectTypeString.toUpperCase().substring(0, 2); + String objectTypeHexString = Util.toUpperInvariant(objectTypeString.substring(0, 2)); int objectTypeInt = Integer.parseInt(objectTypeHexString, 16); mimeType = getMimeTypeFromMp4ObjectType(objectTypeInt); } catch (NumberFormatException ignored) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/core/src/main/java/com/google/android/exoplayer2/util/Util.java index 4ee240e419..0a4a38697e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -329,6 +329,16 @@ public final class Util { 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}. * diff --git a/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylistParserTest.java b/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylistParserTest.java index b10997cfe9..5ba6f0c7f4 100644 --- a/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylistParserTest.java +++ b/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylistParserTest.java @@ -20,12 +20,12 @@ import static com.google.common.truth.Truth.assertThat; import android.net.Uri; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment; +import com.google.android.exoplayer2.util.Util; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.List; -import java.util.Locale; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -122,7 +122,7 @@ public class HlsMediaPlaylistParserTest { .isEqualTo("https://priv.example.com/key.php?r=2682"); // 0xA7A == 2682. 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.byterangeOffset).isEqualTo(2147586650L); 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"); // 0xA7B == 2683. 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.byterangeOffset).isEqualTo(0); assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");