Skip to content

Commit

Permalink
Remove URL sanitizer as it is malfunctioning and unclear where needed #…
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Jan 19, 2016
1 parent 14cbbb1 commit 5d16ed7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 58 deletions.
3 changes: 0 additions & 3 deletions src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public static void openExternalViewer(MetaData metaData, String link, String fie
} else if ("eprint".equals(fieldName)) {
fieldName = "url";

link = URLUtil.sanitizeUrl(link);

// Check to see if link field already contains a well formated URL
if (!link.startsWith("http://")) {
link = Util.ARXIV_LOOKUP_PREFIX + link;
Expand Down Expand Up @@ -427,7 +425,6 @@ private static void openFolderAndSelectFileOnWindows(String link) throws IOExcep
* @throws IOException
*/
public static void openBrowser(String url) throws IOException {
url = URLUtil.sanitizeUrl(url);
ExternalFileType fileType = Globals.prefs.getExternalFileTypeByExt("html");
openExternalFilePlatformIndependent(fileType, url);
}
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/net/sf/jabref/logic/util/io/URLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,4 @@ public static String cleanGoogleSearchURL(String url) {
}
}

/**
* Make sure an URL is "portable", in that it doesn't contain bad characters that break the open command in some
* OSes. A call to this method will also remove \\url{} enclosings.
*
* It does:
* - trim whitespace
* - remove Latex \\url{} tags
*
* @param link the URL to sanitize.
* @return the sanitized URL
*/
public static String sanitizeUrl(String link) {
// remove whitespace
link = link.trim();

// Remove \\url{}
if (link.startsWith("\\url{") && link.endsWith("}")) {
link = link.substring(5, link.length() - 1);
}

// FIXME: everything below is really flawed atm
link = link.replaceAll("\\+", "%2B");

try {
link = URLDecoder.decode(link, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ignored) {
// Ignored
}

/**
* Fix for: [ 1574773 ] sanitizeUrl() breaks ftp:// and file:///
*
* http://sourceforge.net/tracker/index.php?func=detail&aid=1574773&group_id=92314&atid=600306
*/
try {
return new URI(null, link, null).toASCIIString();
} catch (URISyntaxException e) {
return link;
}
}
}
15 changes: 0 additions & 15 deletions src/test/java/net/sf/jabref/logic/util/io/URLUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,4 @@ public void cleanGoogleSearchURL() throws Exception {
URLUtil.cleanGoogleSearchURL("https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCEQFjAAahUKEwjJurHd2sfHAhWBsxQKHSrEAaM&url=ftp%3A%2F%2Fmoz.com%2Fugc%2Fthe-ultimate-guide-to-the-google-search-parameters&ei=0THeVYmOJIHnUqqIh5gK&usg=AFQjCNHnid_r_d2LP8_MqvI7lQnTC3lB_g&sig2=ICzxDroG2ENTJSUGmdhI2w")
);
}

@Test
public void testSanitizeUrl() {
Assert.assertEquals("http://www.vg.no", URLUtil.sanitizeUrl("http://www.vg.no"));
Assert.assertEquals("http://www.vg.no/fil%20e.html", URLUtil.sanitizeUrl("http://www.vg.no/fil e.html"));
Assert.assertEquals("http://www.vg.no/fil%20e.html", URLUtil.sanitizeUrl("http://www.vg.no/fil%20e.html"));
Assert.assertEquals("www.vg.no/fil%20e.html", URLUtil.sanitizeUrl("www.vg.no/fil%20e.html"));
Assert.assertEquals("www.vg.no/fil%20e.html", URLUtil.sanitizeUrl("\\url{www.vg.no/fil%20e.html}"));
Assert.assertEquals("ftp://www.vg.no", URLUtil.sanitizeUrl("ftp://www.vg.no"));
Assert.assertEquals("file://doof.txt", URLUtil.sanitizeUrl("file://doof.txt"));
Assert.assertEquals("file:///", URLUtil.sanitizeUrl("file:///"));
Assert.assertEquals("/src/doof.txt", URLUtil.sanitizeUrl("/src/doof.txt"));
Assert.assertEquals("/", URLUtil.sanitizeUrl("/"));
Assert.assertEquals("/home/user/example.txt", URLUtil.sanitizeUrl("/home/user/example.txt"));
}
}

0 comments on commit 5d16ed7

Please sign in to comment.