Skip to content

Conversation

@florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Nov 6, 2025

Closes #4600.

This extends the topic filter for the event WebSocket to support RegEx in addition to the existing * wildcard expressions.
This works by:

  1. Checking if a filter topic matches the existing syntax, optionally including the * wildcard
  2. Assuming the a filter topic is a RegEx if it does not match in 1.
  3. If Pattern Compilation fails, throw an EventProcessingException as previously when a filter topic was invalid.

@florian-h05 florian-h05 requested a review from a team as a code owner November 6, 2025 13:21
@florian-h05
Copy link
Contributor Author

When updating the docs after this has been merged, don’t forget to correct the docs, that the * wildcard does match multiple topic segments.

@kaikreuzer kaikreuzer requested a review from Copilot December 27, 2025 23:05
@kaikreuzer
Copy link
Member

@florian-h05 Could you please rebase this PR?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the event WebSocket topic filter to support regular expressions in addition to the existing wildcard (*) pattern matching. The implementation introduces a TopicFilterMapper class that determines whether a topic filter is a simple pattern (using word characters, slashes, and optional asterisks) or a regular expression. Simple patterns are converted to regex with wildcard expansion and anchoring, while regex patterns are used directly. The change refactors the filter processing logic from EventWebSocket into the new mapper class, improves error handling by passing PatternSyntaxException through the chain, and adds comprehensive test coverage for the new regex functionality.

Key Changes

  • Introduced TopicFilterMapper class to handle conversion of topic expressions to regex patterns, supporting both simple wildcard syntax and full regex
  • Extended TopicEventFilter constructor to declare PatternSyntaxException for better error transparency
  • Added comprehensive test cases covering regex patterns in both include and exclude topic filters

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
TopicFilterMapper.java New class that maps topic filter expressions to TopicEventFilter, handling both simple wildcard patterns and regex patterns
TopicEventFilter.java Updated constructor to declare PatternSyntaxException and corrected JavaDoc
EventWebSocket.java Refactored topic filter logic to use TopicFilterMapper instead of inline processing
EventProcessingException.java Added constructor accepting both message and cause for better exception chaining
EventWebSocketTest.java Enhanced tests to cover regex patterns in both include and exclude filters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@florian-h05 florian-h05 force-pushed the eventwebsocket-topicsfilter-regex branch from c5bdb4b to 5bc42d2 Compare December 28, 2025 14:31
Signed-off-by: Florian Hotze <[email protected]>
@florian-h05
Copy link
Contributor Author

@kaikreuzer Done

@kaikreuzer kaikreuzer merged commit a90149b into openhab:main Jan 6, 2026
4 checks passed
@kaikreuzer kaikreuzer added the enhancement An enhancement or new feature of the Core label Jan 6, 2026
@kaikreuzer kaikreuzer added this to the 5.2 milestone Jan 6, 2026
@florian-h05 florian-h05 deleted the eventwebsocket-topicsfilter-regex branch January 6, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify filter mechanism

2 participants