Skip to content

Commit

Permalink
Check if FileDrop URLs need to be URL-encoded first, add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielsherry committed Sep 1, 2024
1 parent 40d33e5 commit 28c156a
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
Expand Down Expand Up @@ -337,8 +338,16 @@ private static File[] createFileArray(BufferedReader bReader) {
if (ZERO_CHAR_STRING.equals(line))
continue;

// Clean up this line and check if it needs to be URL encoded before being read as a URL
line = line.strip();
if (line.contains(" ") && !line.contains("%")) {
line = URLEncoder.encode(line, "UTF-8");
}

// Turn it into a File and add it to the list
File file = new File(new URI(line));
list.add(file);

} catch (Exception ex) {
log("Error with " + line + ": " + ex.getMessage());
}
Expand Down Expand Up @@ -412,21 +421,25 @@ private DropType isDragOk(final java.awt.dnd.DropTargetDragEvent evt) {

// If it's a file list flavour, accept it
if (curFlavor.equals(DataFlavor.javaFileListFlavor)) {
log("FileDrop: Found a DropType of " + DropType.DROP_FILELIST.toString());
return DropType.DROP_FILELIST;
}

// if the mime-type is a uri-list, accept it
if (curFlavor.getSubType().equals("uri-list") && curFlavor.isRepresentationClassReader()) {
log("FileDrop: Found a DropType of " + DropType.DROP_LINUX.toString());
return DropType.DROP_LINUX;
}

// if the String payload is a URL, accept it
if (isDragUrl(evt)) {
log("FileDrop: Found a DropType of " + DropType.DROP_URL.toString());
return DropType.DROP_URL;
}

}

log("FileDrop: Found a DropType of " + DropType.DROP_FAIL.toString());
return DropType.DROP_FAIL;


Expand Down

0 comments on commit 28c156a

Please sign in to comment.