aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/service/TagServiceImpl.java2
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java
index 93edcccc..0bd6bb0c 100644
--- a/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/src/main/java/com/juick/service/TagServiceImpl.java
@@ -221,7 +221,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
public Pair<String, List<Tag>> fromString(final String txt) {
String firstLine = txt.split("\\n", 2)[0];
Supplier<Stream<String>> tagsStream = () -> Arrays.stream(firstLine.split("\\ "))
- .takeWhile(t -> !t.equals("*") && t.startsWith("*"));
+ .takeWhile(t -> t.matches("\\*[^\\s]+|#[^\\s]*[^\\d][^\\s]*"));
int tagsLength = tagsStream.get().collect(Collectors.joining(" ")).length();
String body = txt.substring(tagsLength);
List<Tag> tags = tagsStream.get().map(t -> getTag(t.substring(1), true))
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 795415be..c37d70bc 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -437,6 +437,18 @@ public class ServerTests {
}
@Test
+ public void tagParsingTests() {
+ assertEquals(0, tagService.fromString("*").getRight().size());
+ assertEquals(1, tagService.fromString("*kek").getRight().size());
+ assertEquals(1, tagService.fromString("*123").getRight().size());
+ assertEquals(0, tagService.fromString("#").getRight().size());
+ assertEquals(1, tagService.fromString("#kek").getRight().size());
+ assertEquals(1, tagService.fromString("#12k").getRight().size());
+ assertEquals(0, tagService.fromString("#123").getRight().size());
+ assertEquals(2, tagService.fromString("#mixed *tags #123 test").getRight().size());
+ }
+
+ @Test
public void likeTypeStatsTests() {
User dsdss = userService.createUser("dsdss", "secret").orElseThrow(IllegalStateException::new);
final int freefdId = freefd.getUid();