Skip to content

Commit

Permalink
Fix Recent Files URI Patch
Browse files Browse the repository at this point in the history
Initial patch would break non-file URIs if they did work. Instead we can
simply check if a file exists at the filepath. If it does, then it's
clearly a filepath and not a URI. Otherwise, we can try it as a URI, and
if it is syntactically correct and absolute with a scheme present, we
can use it as-is.
  • Loading branch information
RobertBColton committed Mar 25, 2021
1 parent 391d1c7 commit 284ab76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion org/lateralgm/main/LGM.java
Expand Up @@ -128,7 +128,7 @@

public final class LGM
{
public static final String version = "1.8.227"; //$NON-NLS-1$
public static final String version = "1.8.228"; //$NON-NLS-1$

// TODO: This list holds the class loader for any loaded plugins which should be
// cleaned up and closed when the application closes.
Expand Down
28 changes: 24 additions & 4 deletions org/lateralgm/main/PrefsStore.java
Expand Up @@ -11,6 +11,8 @@

import java.awt.Rectangle;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.prefs.BackingStoreException;
Expand Down Expand Up @@ -81,10 +83,28 @@ public static void patchRecentFiles()
{
if (i > 0) sb.append(" ");
String str = array[i];
if (!str.startsWith("file%3A%2F"))
sb.append(Util.urlEncode(new File(Util.urlDecode(str)).toURI().toString()));
else
sb.append(str);
String strDecoded = Util.urlDecode(str);
File file = new File(strDecoded);
if (!file.exists())
{
try
{
URI uri = new URI(strDecoded);

// URI has a scheme and is not relative, use as-is
if (uri.isAbsolute())
{
sb.append(str);
continue;
}
}
catch (URISyntaxException e)
{ // fall through, assume filepath
}
}

// convert filepath to file scheme URI and reencode
sb.append(Util.urlEncode(file.toURI().toString()));
}
PREFS.put("FILE_RECENT",sb.toString());
}
Expand Down

0 comments on commit 284ab76

Please sign in to comment.