Skip to content

Commit

Permalink
Use a precompiled pattern in ChannelUID.validateSegment (#4327)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
  • Loading branch information
joerg1985 authored Jul 23, 2024
1 parent 8557666 commit f502e9d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -30,7 +31,7 @@
@NonNullByDefault
public class ChannelUID extends UID {

public static final String CHANNEL_SEGMENT_PATTERN = "[\\w-]*|[\\w-]*#[\\w-]*";
public static final Pattern CHANNEL_SEGMENT_PATTERN = Pattern.compile("[\\w-]*(?:#[\\w-]*)?");
public static final String CHANNEL_GROUP_SEPARATOR = "#";

/**
Expand Down Expand Up @@ -132,7 +133,7 @@ protected void validateSegment(String segment, int index, int length) {
if (index < length - 1) {
super.validateSegment(segment, index, length);
} else {
if (!segment.matches(CHANNEL_SEGMENT_PATTERN)) {
if (!CHANNEL_SEGMENT_PATTERN.matcher(segment).matches()) {
throw new IllegalArgumentException(String.format(
"UID segment '%s' contains invalid characters. The last segment of the channel UID must match the pattern '%s'.",
segment, CHANNEL_SEGMENT_PATTERN));
Expand Down

0 comments on commit f502e9d

Please sign in to comment.