diff --git a/src/main/java/com/commafeed/backend/feeds/FeedParser.java b/src/main/java/com/commafeed/backend/feeds/FeedParser.java index 349ac4a5..6cce1fa8 100644 --- a/src/main/java/com/commafeed/backend/feeds/FeedParser.java +++ b/src/main/java/com/commafeed/backend/feeds/FeedParser.java @@ -76,7 +76,9 @@ public class FeedParser { entry.setGuid(FeedUtils.truncate(item.getUri(), 2048)); entry.setGuidHash(DigestUtils.sha1Hex(item.getUri())); - entry.setUrl(FeedUtils.truncate(item.getLink(), 2048)); + entry.setUrl(FeedUtils.toAbsoluteUrl( + FeedUtils.truncate(item.getLink(), 2048), + feed.getLink())); entry.setUpdated(validateDate(getUpdateDate(item))); entry.setAuthor(FeedUtils.truncate(item.getAuthor(), 128)); diff --git a/src/main/java/com/commafeed/backend/feeds/FeedUtils.java b/src/main/java/com/commafeed/backend/feeds/FeedUtils.java index 6f7eeabc..fa0e543f 100644 --- a/src/main/java/com/commafeed/backend/feeds/FeedUtils.java +++ b/src/main/java/com/commafeed/backend/feeds/FeedUtils.java @@ -185,4 +185,23 @@ public class FeedUtils { Collections.reverse(timestamps); return timestamps; } + + public static String removeTrailingSlash(String url) { + if (url.endsWith("/")) { + url = url.substring(0, url.length() - 1); + } + return url; + } + + public static String toAbsoluteUrl(String url, String baseUrl) { + if (baseUrl == null || url == null || url.startsWith("http")) { + return url; + } + + if (url.startsWith("/") == false) { + url = "/" + url; + } + + return baseUrl + url; + } } diff --git a/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java b/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java index 911227d8..7a2bf472 100644 --- a/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java +++ b/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java @@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory; import com.commafeed.backend.HttpGetter; import com.commafeed.backend.dao.FeedPushInfoDAO; +import com.commafeed.backend.feeds.FeedUtils; import com.commafeed.backend.model.Feed; import com.commafeed.backend.model.FeedPushInfo; import com.commafeed.backend.services.ApplicationSettingsService; @@ -39,10 +40,9 @@ public class SubscriptionHandler { FeedPushInfo info = feed.getPushInfo(); String hub = info.getHub(); String topic = info.getTopic(); - String publicUrl = applicationSettingsService.get().getPublicUrl(); - if (publicUrl.endsWith("/")) { - publicUrl = publicUrl.substring(0, publicUrl.length() - 1); - } + String publicUrl = FeedUtils + .removeTrailingSlash(applicationSettingsService.get() + .getPublicUrl()); log.debug("sending new pubsub subscription to {} for {}", hub, topic); diff --git a/src/main/java/com/commafeed/frontend/pages/GoogleImportCallbackPage.java b/src/main/java/com/commafeed/frontend/pages/GoogleImportCallbackPage.java index 3b8b5824..ad0f4ca9 100644 --- a/src/main/java/com/commafeed/frontend/pages/GoogleImportCallbackPage.java +++ b/src/main/java/com/commafeed/frontend/pages/GoogleImportCallbackPage.java @@ -9,6 +9,7 @@ import org.apache.wicket.request.mapper.parameter.PageParameters; import com.commafeed.backend.StartupBean; import com.commafeed.backend.dao.UserDAO; +import com.commafeed.backend.feeds.FeedUtils; import com.commafeed.backend.feeds.OPMLImporter; import com.commafeed.backend.model.ApplicationSettings; import com.commafeed.backend.model.User; @@ -44,10 +45,7 @@ public class GoogleImportCallbackPage extends WebPage { UserDAO userDAO; public static String getCallbackUrl(String publicUrl) { - if (publicUrl.endsWith("/")) { - publicUrl = publicUrl.substring(0, publicUrl.length() - 1); - } - return publicUrl + "/" + PAGE_PATH; + return FeedUtils.removeTrailingSlash(publicUrl) + "/" + PAGE_PATH; } public GoogleImportCallbackPage(PageParameters params) { diff --git a/src/main/java/com/commafeed/frontend/pages/PasswordRecoveryPage.java b/src/main/java/com/commafeed/frontend/pages/PasswordRecoveryPage.java index d28368ec..d5448a37 100644 --- a/src/main/java/com/commafeed/frontend/pages/PasswordRecoveryPage.java +++ b/src/main/java/com/commafeed/frontend/pages/PasswordRecoveryPage.java @@ -14,6 +14,7 @@ import org.apache.wicket.model.Model; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.commafeed.backend.feeds.FeedUtils; import com.commafeed.backend.model.User; import com.commafeed.frontend.pages.components.BootstrapFeedbackPanel; @@ -67,10 +68,9 @@ public class PasswordRecoveryPage extends BasePage { private String buildEmailContent(User user) throws Exception { - String publicUrl = applicationSettingsService.get().getPublicUrl(); - if (publicUrl.endsWith("/")) { - publicUrl = publicUrl.substring(0, publicUrl.length() - 1); - } + String publicUrl = FeedUtils + .removeTrailingSlash(applicationSettingsService.get() + .getPublicUrl()); publicUrl += "/recover2"; return String