aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java25
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java13
2 files changed, 26 insertions, 12 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
index 403dac09..63e07bd2 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
@@ -224,20 +224,21 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
@Override
public List<Tag> fromString(final String txt, final boolean tagsOnly) {
Pattern tagsPattern = tagsOnly ? TAGS_PATTERN1 : TAGS_PATTERN2;
-
- if (tagsPattern.matcher(txt).matches()) {
- Matcher tagMatcher = TAG_PATTERN.matcher(txt);
-
- List<Tag> tags = new ArrayList<>();
-
- // TODO: process readonly, private, friends, public
- while (tagMatcher.find()) {
- for (int i = 1; i <= tagMatcher.groupCount(); i++)
- tags.add(getTag(tagMatcher.group(i), true));
+ List<Tag> tags = new ArrayList<>();
+ for (String line : txt.split("\n")) {
+ if (line.startsWith(">"))
+ continue;
+ if (tagsPattern.matcher(line).matches()) {
+ Matcher tagMatcher = TAG_PATTERN.matcher(line);
+
+ // TODO: process readonly, private, friends, public
+ while (tagMatcher.find()) {
+ for (int i = 1; i <= tagMatcher.groupCount(); i++)
+ tags.add(getTag(tagMatcher.group(i), true));
+ }
}
- return tags;
}
- return Collections.emptyList();
+ return tags;
}
@Transactional(readOnly = true)
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index e23116ad..e8111239 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -754,6 +754,19 @@ public class ServerTests {
commandsManager.processCommand(user, "D #" + mid, emptyUri).getText());
assertEquals("should be not found", "Message not found",
commandsManager.processCommand(user, "#" + mid, emptyUri).getText());
+
+ String expectedCodeMessage = "some smelly code goes here\n" +
+ "> void main(void** args) {\n" +
+ "> }";
+ String codeAndTags = "*code\n" + expectedCodeMessage;
+ Message codeAndTagsMessage = commandsManager.processCommand(user, codeAndTags, emptyUri).getNewMessage().get();
+ List<Tag> codeAndTagsTags = codeAndTagsMessage.getTags();
+ assertEquals("expected single tag", 1,
+ codeAndTagsTags.size());
+ assertEquals("the single tag should be the 'code'", "code",
+ codeAndTagsTags.get(0).getName());
+ assertEquals("and the message should be with a C-code and without tags", expectedCodeMessage,
+ codeAndTagsMessage.getText());
}
@Test
public void mailParserTest() throws Exception {