From 50ba523bab3a1ea66f98f1b1ab3b46463df14949 Mon Sep 17 00:00:00 2001 From: rongtong Date: Tue, 7 Jan 2020 20:13:26 +0800 Subject: [PATCH] [ISSUE #1699] Fix wrong topic max length in TopicValidator (#1700) * fix(topicValidator):fix topic max length to 127 * test(topicValidator):modify relate tests --- .../org/apache/rocketmq/broker/topic/TopicValidator.java | 6 +++--- .../apache/rocketmq/broker/topic/TopicValidatorTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicValidator.java b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicValidator.java index 8b534764..58b1cc86 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicValidator.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicValidator.java @@ -27,7 +27,7 @@ public class TopicValidator { private static final String VALID_PATTERN_STR = "^[%|a-zA-Z0-9_-]+$"; private static final Pattern PATTERN = Pattern.compile(VALID_PATTERN_STR); - private static final int CHARACTER_MAX_LENGTH = 255; + private static final int TOPIC_MAX_LENGTH = 127; private static boolean regularExpressionMatcher(String origin, Pattern pattern) { if (pattern == null) { @@ -51,9 +51,9 @@ public class TopicValidator { return false; } - if (topic.length() > CHARACTER_MAX_LENGTH) { + if (topic.length() > TOPIC_MAX_LENGTH) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark("The specified topic is longer than topic max length 255."); + response.setRemark("The specified topic is longer than topic max length."); return false; } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicValidatorTest.java b/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicValidatorTest.java index 267931fd..78be63fc 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicValidatorTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/topic/TopicValidatorTest.java @@ -47,10 +47,10 @@ public class TopicValidatorTest { assertThat(response.getRemark()).contains("The specified topic is conflict with AUTO_CREATE_TOPIC_KEY_TOPIC."); clearResponse(response); - res = TopicValidator.validateTopic(generateString(255), response); + res = TopicValidator.validateTopic(generateString(128), response); assertThat(res).isFalse(); assertThat(response.getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR); - assertThat(response.getRemark()).contains("The specified topic is longer than topic max length 255."); + assertThat(response.getRemark()).contains("The specified topic is longer than topic max length."); } -- GitLab