[Android] Media: fix UriFromMrl

Thomas Guillem git at videolan.org
Tue Sep 15 16:31:54 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Sep 15 16:31:03 2015 +0200| [6abac6231c703467fc5fe4bef55b45f2fce1b60a] | committer: Thomas Guillem

Media: fix UriFromMrl

Continue to parse in case of error since the % character can be escaped.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6abac6231c703467fc5fe4bef55b45f2fce1b60a
---

 libvlc/src/org/videolan/libvlc/Media.java |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index ca1c73e..3a33874 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -306,15 +306,18 @@ public class Media extends VLCObject<Media.Event> {
         for (int i = 0; i < array.length; ++i) {
             final char c = array[i];
             if (c == '%') {
-                if (array.length - i < 3)
-                    throw new IllegalArgumentException("bad mrl format");
-
-                final int hex = Integer.parseInt(new String(array, i + 1, 2), 16);
-                if (URI_AUTHORIZED_CHARS.indexOf(hex) != -1) {
-                    sb.append((char)hex);
-                    i += 2;
-                    continue;
+                if (array.length - i >= 3) {
+                    try {
+                        final int hex = Integer.parseInt(new String(array, i + 1, 2), 16);
+                        if (URI_AUTHORIZED_CHARS.indexOf(hex) != -1) {
+                            sb.append((char) hex);
+                            i += 2;
+                            continue;
+                        }
+                    } catch (NumberFormatException ignored) {
+                    }
                 }
+
             }
             sb.append(c);
         }



More information about the Android mailing list