Fixes Bug #17844 Hashtag does not support numbers e.g. #4.15.0
Fixes Bug #17811 Avoid # being considered an hastagged topic
This commit is contained in:
parent
2c0614a7d0
commit
004db5a034
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.socialnetworking</groupId>
|
<groupId>org.gcube.socialnetworking</groupId>
|
||||||
<artifactId>social-util-library</artifactId>
|
<artifactId>social-util-library</artifactId>
|
||||||
<version>1.7.1</version>
|
<version>1.7.2-SNAPSHOT</version>
|
||||||
<name>social-util-library</name>
|
<name>social-util-library</name>
|
||||||
<description>
|
<description>
|
||||||
The social-util-library contains utility functions that can be used by the social-networking portlets.
|
The social-util-library contains utility functions that can be used by the social-networking portlets.
|
||||||
|
|
|
@ -6,10 +6,10 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SanitizedHashTag {
|
public class SanitizedHashTag {
|
||||||
|
|
||||||
private static final String RECOGNIZE_HASHTAG_REGEX = "^.{0,3}#[\\w-]*[\\W]{0,3}";
|
private static final String RECOGNIZE_HASHTAG_REGEX = "^.{0,3}#[\\w.-]{1,}[\\W]{0,3}";
|
||||||
private static final Pattern RECOGNIZE_HASHTAG_PATTERN;
|
private static final Pattern RECOGNIZE_HASHTAG_PATTERN;
|
||||||
|
|
||||||
private static final String HASHTAG_REGEX = "#[\\w-]*";
|
private static final String HASHTAG_REGEX = "#[\\w.-]{1,}";
|
||||||
private static final Pattern HASHTAG_PATTERN;
|
private static final Pattern HASHTAG_PATTERN;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -41,6 +41,11 @@ public class SanitizedHashTag {
|
||||||
prefix = string.substring(0,matcher.start());
|
prefix = string.substring(0,matcher.start());
|
||||||
hashTag = string.substring(matcher.start(), matcher.end());
|
hashTag = string.substring(matcher.start(), matcher.end());
|
||||||
postfix = string.substring(matcher.end());
|
postfix = string.substring(matcher.end());
|
||||||
|
if (hashTag.endsWith(".")) {
|
||||||
|
hashTag = hashTag.substring(0, hashTag.length()-1);
|
||||||
|
postfix += ".";
|
||||||
|
}
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
throw new IllegalArgumentException(string + " is not a valid TAG");
|
throw new IllegalArgumentException(string + " is not a valid TAG");
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,18 +125,34 @@ public class MessageParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTest() {
|
public void testTest() {
|
||||||
String text = "Hello (https://doodle.com/poll/not-existing-poll)";
|
String text = "Hello (https://doodle.com/poll/not-existing-poll)";
|
||||||
logger.debug(findFirstLink(text));
|
logger.debug(findFirstLink(text));
|
||||||
|
|
||||||
text = "post \"a text with #hashtag);\"";
|
text = "post \"a text with #hashtag);\"";
|
||||||
SocialMessageParser messageParser = new SocialMessageParser(text);
|
SocialMessageParser messageParser = new SocialMessageParser(text);
|
||||||
logger.debug(messageParser.getParsedMessage());
|
logger.debug(messageParser.getParsedMessage());
|
||||||
|
|
||||||
text = "\"#hashtag and #hashtag repeated.";
|
text = "\"#hashtag and #hashtag repeated.";
|
||||||
messageParser = new SocialMessageParser(text);
|
messageParser = new SocialMessageParser(text);
|
||||||
logger.debug(messageParser.getParsedMessage());
|
logger.debug(messageParser.getParsedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkHashTag7() throws Exception {
|
||||||
|
String text = "Checking hashtag between quotes #hashtag1; #hashtag1, #hashtag3. \"#hashtag5\" is recognized (#anotherHashtag) #4. #4.12 # ";
|
||||||
|
SocialMessageParser messageParser = new SocialMessageParser(text);
|
||||||
|
logger.debug(messageParser.getParsedMessage());
|
||||||
|
List<String> htags = messageParser.getHashtags();
|
||||||
|
for (String hTag : htags) {
|
||||||
|
logger.debug("found hashtag:"+hTag);
|
||||||
|
}
|
||||||
|
logger.debug("messageParser.getHashtags().size() should be 7, is: "+ htags.size());
|
||||||
|
Assert.assertTrue(htags.size() == 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkHashTag() throws Exception {
|
public void checkHashTag() throws Exception {
|
||||||
String token = "\"#hashtag\"";
|
String token = "\"#hashtag\"";
|
||||||
|
@ -173,6 +189,7 @@ public class MessageParserTest {
|
||||||
Assert.assertTrue(sanitizedHashTag.getPostfix().compareTo("\");")==0);
|
Assert.assertTrue(sanitizedHashTag.getPostfix().compareTo("\");")==0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void checkHashTag4() throws Exception {
|
public void checkHashTag4() throws Exception {
|
||||||
String token = ";(\"#hashtag\");]";
|
String token = ";(\"#hashtag\");]";
|
||||||
|
|
Loading…
Reference in New Issue