Skip to content

Commit c367c8c

Browse files
author
Chenhe
committed
修复无法匹配换行消息
1 parent 8e2f490 commit c367c8c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

app/src/main/java/cc/chenhe/qqnotifyevo/core/NotificationProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class NotificationProcessor(context: Context) {
5858
* 限制:昵称不能包含英文括号 `()`.
5959
*/
6060
@VisibleForTesting
61-
val groupMsgPattern: Pattern = Pattern.compile("^(.+?)\\((.+)\\):(.+)$")
61+
val groupMsgPattern: Pattern = Pattern.compile("^(.+?)\\((.+)\\):([\\s\\S]+)$")
6262

6363
// 私聊消息
6464
// title: 昵称 | 昵称 (x条新消息) //特别关心前缀:[特别关心]
@@ -71,7 +71,7 @@ abstract class NotificationProcessor(context: Context) {
7171
* Group: 1昵称, 2消息内容
7272
*/
7373
@VisibleForTesting
74-
val msgPattern: Pattern = Pattern.compile("^(.+?): (.+)$")
74+
val msgPattern: Pattern = Pattern.compile("^(.+?): ([\\s\\S]+)$")
7575

7676
/**
7777
* 匹配私聊消息 Title.

app/src/test/java/cc/chenhe/qqnotifyevo/core/NotificationProcessorTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class NotificationProcessorTest {
3636
matcher.group(3)!! shouldBeEqualTo "Hello~"
3737
}
3838

39+
@Test
40+
fun group_ticker_match_multiLines() {
41+
val ticker = generateGroupTicker("Bob", "Family(1)", "Hello\nhere\nyep")
42+
val matcher = NotificationProcessor.groupMsgPattern.matcher(ticker)
43+
matcher.matches().shouldBeTrue()
44+
45+
matcher.group(1)!! shouldBeEqualTo "Bob"
46+
matcher.group(2)!! shouldBeEqualTo "Family(1)"
47+
matcher.group(3)!! shouldBeEqualTo "Hello\nhere\nyep"
48+
}
49+
3950
@Test
4051
fun group_ticker_mismatch_friend() {
4152
val ticker = generateFriendTicker("Bob", "Hello~")
@@ -53,6 +64,16 @@ class NotificationProcessorTest {
5364
matcher.group(2)!! shouldBeEqualTo "hi"
5465
}
5566

67+
@Test
68+
fun friend_ticker_match_multiLines() {
69+
val ticker = generateFriendTicker("Alice", "hi\nok\nthanks")
70+
val matcher = NotificationProcessor.msgPattern.matcher(ticker)
71+
matcher.matches().shouldBeTrue()
72+
73+
matcher.group(1)!! shouldBeEqualTo "Alice"
74+
matcher.group(2)!! shouldBeEqualTo "hi\nok\nthanks"
75+
}
76+
5677
@Test
5778
fun friend_ticker_mismatch_group() {
5879
val ticker = generateGroupTicker("Alice", "group", "hi")

0 commit comments

Comments
 (0)