Skip to content

Commit

Permalink
fix(desktop): improve MQTT wildcard topic matching for '#'
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Aug 28, 2024
1 parent 29aaa8d commit 5632e97
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/database/services/MessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class MessageService {
if (topic && topic !== '#') {
topic = topic.replace(/[\\%_]/g, '\\$&')
if (topic.startsWith('$share/')) topic = topic.split('/').slice(2).join('/')
if (topic.includes('#')) topic = topic.replace('/#', '%')
if (topic.includes('#') && topic.endsWith('/#')) topic = topic.replace('#', '%')
/*
Known Issue: '+' wildcard handling in MQTT topics is incorrect.
'+' is replaced with '%' for SQL LIKE, causing multi-level match.
Expand Down Expand Up @@ -127,7 +127,7 @@ export default class MessageService {
if (topic && topic !== '#') {
topic = topic.replace(/[\\%_]/g, '\\$&')
if (topic.startsWith('$share/')) topic = topic.split('/').slice(2).join('/')
if (topic.includes('#')) topic = topic.replace('/#', '%')
if (topic.includes('#') && topic.endsWith('/#')) topic = topic.replace('#', '%')
if (topic.includes('+')) topic = topic.replace('+', '%')
query.andWhere('msg.topic LIKE :topic ESCAPE "\\"', { topic })
}
Expand Down

0 comments on commit 5632e97

Please sign in to comment.