mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
fix relative url detection (#699)
This commit is contained in:
@@ -430,12 +430,8 @@ public class FeedUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRelative(final String url) {
|
public static boolean isRelative(final String url) {
|
||||||
// the regex means "doesn't start with 'scheme://'"
|
// the regex means "start with 'scheme://'"
|
||||||
if ((url != null) && (url.startsWith("/") == false) && (!url.matches("^\\w+\\:\\/\\/.*")) && !(url.startsWith("#"))) {
|
return url.startsWith("/") || url.startsWith("#") || !url.matches("^\\w+\\:\\/\\/.*");
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFaviconUrl(FeedSubscription subscription, String publicUrl) {
|
public static String getFaviconUrl(FeedSubscription subscription, String publicUrl) {
|
||||||
|
|||||||
@@ -44,11 +44,18 @@ public class FeedUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testToAbsoluteUrl() {
|
public void testToAbsoluteUrl() {
|
||||||
String expected = "http://a.com/blog/entry/1";
|
String expected = "http://a.com/blog/entry/1";
|
||||||
|
|
||||||
|
// usual cases
|
||||||
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("http://a.com/blog/entry/1", "http://a.com/feed/", "http://a.com/feed/"));
|
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("http://a.com/blog/entry/1", "http://a.com/feed/", "http://a.com/feed/"));
|
||||||
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("http://a.com/blog/entry/1", "http://a.com/feed", "http://a.com/feed"));
|
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("http://a.com/blog/entry/1", "http://a.com/feed", "http://a.com/feed"));
|
||||||
|
|
||||||
|
// relative links
|
||||||
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("../blog/entry/1", "http://a.com/feed/", "http://a.com/feed/"));
|
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("../blog/entry/1", "http://a.com/feed/", "http://a.com/feed/"));
|
||||||
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("../blog/entry/1", "feed.xml", "http://a.com/feed/feed.xml"));
|
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("../blog/entry/1", "feed.xml", "http://a.com/feed/feed.xml"));
|
||||||
|
|
||||||
|
// root-relative links
|
||||||
|
Assert.assertEquals(expected, FeedUtils.toAbsoluteUrl("/blog/entry/1", "/feed", "http://a.com/feed"));
|
||||||
|
|
||||||
Assert.assertEquals("http://ergoemacs.org/emacs/elisp_all_about_lines.html",
|
Assert.assertEquals("http://ergoemacs.org/emacs/elisp_all_about_lines.html",
|
||||||
FeedUtils.toAbsoluteUrl("elisp_all_about_lines.html", "blog.xml", "http://ergoemacs.org/emacs/blog.xml"));
|
FeedUtils.toAbsoluteUrl("elisp_all_about_lines.html", "blog.xml", "http://ergoemacs.org/emacs/blog.xml"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user