Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingComma
String content = this.brokerController.getConfiguration().getAllConfigsFormatString();
if (content != null && content.length() > 0) {
try {
content = MixAll.adjustConfigForPlatform(content);
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
LOGGER.error("AdminBrokerProcessor#getBrokerConfig: unexpected error, caller={}",
Expand Down
9 changes: 9 additions & 0 deletions common/src/main/java/org/apache/rocketmq/common/MixAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,13 @@ public static boolean topicAllowsLMQ(String topic) {
&& !topic.startsWith(TopicValidator.SYSTEM_TOPIC_PREFIX)
&& !topic.equals(TopicValidator.RMQ_SYS_SCHEDULE_TOPIC);
}

public static String adjustConfigForPlatform(String config) {
if (StringUtils.isNotBlank(config)) {
if (isWindows()) {
config = StringUtils.replace(config, "\\", "\\\\");
}
}
return config;
}
}
39 changes: 39 additions & 0 deletions common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,43 @@ public void testIsLmq() {
testLmq = "%LMQ%GID_TEST";
assertThat(MixAll.isLmq(testLmq)).isTrue();
}

@Test
public void testAdjustConfigForPlatform_OnWindows() {
if (MixAll.isWindows()) {
String configWithSingleBackslash = "data\\path\\config\\file.properties";
String adjusted = MixAll.adjustConfigForPlatform(configWithSingleBackslash);
assertThat(adjusted).isEqualTo("data\\\\path\\\\config\\\\file.properties");
Comment thread
Crazylychee marked this conversation as resolved.

String configWithMultipleBackslashes = "C:\\\\RocketMQ\\\\logs\\\\broker.log";
adjusted = MixAll.adjustConfigForPlatform(configWithMultipleBackslashes);
assertThat(adjusted).isEqualTo("C:\\\\\\\\RocketMQ\\\\\\\\logs\\\\\\\\broker.log");

String configWithoutBackslash = "listenPort=10911";
adjusted = MixAll.adjustConfigForPlatform(configWithoutBackslash);
assertThat(adjusted).isEqualTo("listenPort=10911");

String emptyConfig = "";
adjusted = MixAll.adjustConfigForPlatform(emptyConfig);
assertThat(adjusted).isEqualTo("");

adjusted = MixAll.adjustConfigForPlatform(null);
assertThat(adjusted).isNull();
} else {
String configWithSingleBackslash = "/home/rocketmq/conf/broker.conf";
String adjusted = MixAll.adjustConfigForPlatform(configWithSingleBackslash);
assertThat(adjusted).isEqualTo("/home/rocketmq/conf/broker.conf");

String linuxPathWithBackslash = "some\\directory\\file.txt";
adjusted = MixAll.adjustConfigForPlatform(linuxPathWithBackslash);
assertThat(adjusted).isEqualTo("some\\directory\\file.txt");

String emptyConfig = "";
adjusted = MixAll.adjustConfigForPlatform(emptyConfig);
assertThat(adjusted).isEqualTo("");

adjusted = MixAll.adjustConfigForPlatform(null);
assertThat(adjusted).isNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private RemotingCommand getBrokerConfig(ChannelHandlerContext ctx, RemotingComma
String content = this.brokerContainer.getConfiguration().getAllConfigsFormatString();
if (content != null && content.length() > 0) {
try {
content = MixAll.adjustConfigForPlatform(content);
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
LOGGER.error("", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private RemotingCommand handleGetControllerConfig(ChannelHandlerContext ctx, Rem
String content = this.controllerManager.getConfiguration().getAllConfigsFormatString();
if (content != null && content.length() > 0) {
try {
content = MixAll.adjustConfigForPlatform(content);
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
log.error("getConfig error, ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ private RemotingCommand getConfig(ChannelHandlerContext ctx, RemotingCommand req
String content = this.namesrvController.getConfiguration().getAllConfigsFormatString();
if (StringUtils.isNotBlank(content)) {
try {
content = MixAll.adjustConfigForPlatform(content);
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
log.error("getConfig error, ", e);
Expand Down
Loading