674641734 / zirco-browser

Automatically exported from code.google.com/p/zirco-browser
Other
0 stars 0 forks source link

Attempting to download a file that doesn't have query param causes uncaught exception (HEAD) #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Reproduction: Using HEAD code, attempt to download a file with a URL path that 
doesn't contain a question mark (so no query parameters).

Result: Uncaught IndexOutOfBoundsException from this line: 
http://code.google.com/p/zirco-browser/source/browse/trunk/src/org/zirco/model/i
tems/DownloadItem.java#66

Fix: Replace line 66 with the following (or something like it):

int queryParamStart = mFileName.indexOf("?");
if (queryParamStart > 0) {
    mFileName = mFileName.substring(0, queryParamStart);
}

Note that String.indexOf returns -1 if the value is not found, and 
String.substring throws an exception if endIndex < beginIndex.
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf%28jav
a.lang.String%29
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring%28i
nt,%20int%29

This bug was introduced by the fix to issue #45, but doesn't seem to yet be 
released.

Original issue reported on code.google.com by a.pritch...@psiphon.ca on 7 May 2012 at 5:19

GoogleCodeExporter commented 8 years ago
I missed another bit of code that has the same problem -- the other file that 
was changed in the fix to issue #45.

http://code.google.com/p/zirco-browser/source/browse/trunk/src/org/zirco/ui/runn
ables/DownloadRunnable.java#67

Here's the fixed code for that:

int queryParamStart = fileName.indexOf("?");
if (queryParamStart > 0) {
    fileName = fileName.substring(0, queryParamStart);
}
return fileName;

Original comment by a.pritch...@psiphon.ca on 7 May 2012 at 5:31

GoogleCodeExporter commented 8 years ago
Shame on me for such a bad fix for issue #45... Thank for your great report !

Original comment by J.Devauc...@gmail.com on 8 May 2012 at 10:54

GoogleCodeExporter commented 8 years ago
Fixed in r458.

Original comment by J.Devauc...@gmail.com on 8 May 2012 at 11:15