From 81c7b28c6299beda814874d161b8634fb4137566 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 15 Jan 2021 10:47:39 +0100 Subject: [PATCH] Fixed bug #18356 --- .../socialtoken/SanitizedURL.java | 20 +++++++++++-------- .../socialutillibrary/MessageParserTest.java | 19 +++++++++++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/socialnetworking/socialtoken/SanitizedURL.java b/src/main/java/org/gcube/socialnetworking/socialtoken/SanitizedURL.java index 94245bb..2926e62 100644 --- a/src/main/java/org/gcube/socialnetworking/socialtoken/SanitizedURL.java +++ b/src/main/java/org/gcube/socialnetworking/socialtoken/SanitizedURL.java @@ -21,8 +21,6 @@ public class SanitizedURL { throw new MalformedURLException(); } - - prefix = urlString.substring(0,1); if(prefix.matches(CHARACTERS_TO_REMOVE)) { prefix = urlString.substring(0, 1); @@ -35,16 +33,22 @@ public class SanitizedURL { urlString = "http://" + urlString; } - postfix = urlString.substring(urlString.length()-1); - if(postfix.matches(CHARACTERS_TO_REMOVE)) { - urlString = urlString.substring(0, urlString.length()-1); - }else { - postfix = ""; - } + postfix = ""; + urlString = stripPostfix(urlString); url = new URL(urlString); } + private String stripPostfix(String urlString) { + String testPostFix = urlString.substring(urlString.length()-1); + if(testPostFix.matches(CHARACTERS_TO_REMOVE)) { + postfix = urlString.substring(urlString.length()-1) + postfix; + urlString = urlString.substring(0, urlString.length()-1); + urlString = stripPostfix(urlString); + } + return urlString; + } + public String getPrefix() { return prefix; } diff --git a/src/test/java/org/gcube/social_networking/socialutillibrary/MessageParserTest.java b/src/test/java/org/gcube/social_networking/socialutillibrary/MessageParserTest.java index cd2bca2..8bd5521 100644 --- a/src/test/java/org/gcube/social_networking/socialutillibrary/MessageParserTest.java +++ b/src/test/java/org/gcube/social_networking/socialutillibrary/MessageParserTest.java @@ -56,6 +56,22 @@ public class MessageParserTest { public static final String TEST_LUCA_8 = "Hello this link \"https://virtuoso.parthenos.d4science.org/sparql?default-graph-uri=&query=SELECT+%3Ftype+%28COUNT%28%3Ftype%29+as+%3FtypeCount%29++%0D%0A%09%09%09%09%09WHERE+%7B%5B%5D+a+%3Ftype%7D%0D%0A%09%09%09%09%09GROUP+BY+%3Ftype&format=text%2Fhtml&timeout=0&debug=on\" is a SPARQL query "; + public static final String TEST_BUG_18356 = "Dear B-C colleagues,\n" + + "\n" + + "Just a kind reminder that we look forward to welcoming all of you during the Project’s upcoming Blue-Cloud “Service Exploitation & Sustainability Plan (SE&SP) and Roadmap to 2030” Workshop next Thursday, January 21st (9.30am to 1.30pm). Everyone's welcome for an interactive and productive discussion.\n" + + "\n" + + "Please find here a link to the workshop Agenda (https://data.d4science.net/tfXA), including connection details.\n" + + "\n" + + "As discussed, the workshop will provide an opportunity to share the high-level results of the initial phase of stakeholder consultations towards the B-C Roadmap and to work within the Partnership to discuss and align some of the underlying, strategic concepts and ideas that will set the direction for the B-C SE&SP and B-C Roadmap to 2030.\n" + + "\n" + + "To inform the discussions to be held during the workshop, we have produced a report bringing together all the feedback, messages and recommendations gathered during the initial phase of stakeholder consultations (available here - https://data.d4science.net/JEm7). It is a long document, but we have included a one-page Executive Summary with high-level, key messages & recommendations, in case useful.\n" + + "\n" + + "We look forward to a productive discussion with you next Thursday!\n" + + "\n" + + "Kind regards,\n" + + "Julia"; + + @Test public void test13() { SocialMessageParser messageParser = new SocialMessageParser(TEST_13); @@ -105,7 +121,8 @@ public class MessageParserTest { logger.debug(messageParser.getParsedMessage()); messageParser = new SocialMessageParser(TEST_LUCA_7); logger.debug("{}", messageParser.getParsedMessage()); - + messageParser = new SocialMessageParser(TEST_BUG_18356); + logger.debug("{}", messageParser.getParsedMessage()); } @Test(expected=MalformedURLException.class)