Skip to content

Commit dc594d1

Browse files
AkshayBajajMLMarkLogic Builder
authored andcommitted
DHFPROD-8248: Modules loader encodes files paths at wrong moment
1 parent d01ba6f commit dc594d1

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/LoadUserModulesCommand.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
import java.util.Arrays;
5757
import java.util.Date;
5858
import java.util.List;
59+
import java.net.URLDecoder;
60+
import java.nio.charset.StandardCharsets;
5961

6062

6163
/**
@@ -197,9 +199,18 @@ public void execute(CommandContext context) {
197199
DatabaseClient finalClient = hubConfig.newFinalClient();
198200

199201
Path userModulesPath = hubConfig.getHubPluginsDir();
200-
String baseDir = userModulesPath.normalize().toAbsolutePath().toString();
202+
String baseDir = new String();
203+
String EncodedBaseDir = userModulesPath.normalize().toAbsolutePath().toString();
201204
Path startPath = userModulesPath.resolve("entities");
202205

206+
try {
207+
URLDecoder fileNameDecoder = new URLDecoder();
208+
//This handles the decoding of special characters in a file location path.
209+
baseDir = fileNameDecoder.decode(EncodedBaseDir, StandardCharsets.UTF_8.name());
210+
}
211+
catch (Exception e){
212+
e.printStackTrace();
213+
}
203214
// load any user files under plugins/* int the modules database.
204215
// this will ignore REST folders under entities
205216
DefaultModulesLoader modulesLoader = getStagingModulesLoader(config);
@@ -220,7 +231,17 @@ public void execute(CommandContext context) {
220231
// deploy the auto-generated ES search options, but not if mlWatch is being run, as it will result in the same
221232
// options being generated and loaded over and over
222233
if (loadQueryOptions) {
223-
Path entityConfigDir = Paths.get(hubConfig.getHubProject().getProjectDirString(), HubConfig.ENTITY_CONFIG_DIR);
234+
String gerProjectDir = hubConfig.getHubProject().getProjectDirString();
235+
String decodedFileName=new String();
236+
try {
237+
URLDecoder fileNameDecoder = new URLDecoder();
238+
//This handles the decoding of special characters in a file location path
239+
decodedFileName = fileNameDecoder.decode(gerProjectDir, StandardCharsets.UTF_8.name());
240+
}
241+
catch (Exception e){
242+
e.printStackTrace();
243+
}
244+
Path entityConfigDir = Paths.get(decodedFileName, HubConfig.ENTITY_CONFIG_DIR);
224245
if (!entityConfigDir.toFile().exists()) {
225246
entityConfigDir.toFile().mkdirs();
226247
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2021 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.hub.deploy.commands;
17+
18+
import com.marklogic.hub.AbstractHubCoreTest;
19+
import com.marklogic.hub.impl.Versions;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
24+
import java.net.URLDecoder;
25+
import java.nio.charset.StandardCharsets;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
29+
public class LoadUserModulesCommandTest extends AbstractHubCoreTest {
30+
31+
@Autowired
32+
Versions versions;
33+
34+
@BeforeEach
35+
public void setupEach() {
36+
installProjectInFolder("flow-runner-test");
37+
}
38+
39+
@Test
40+
void testDecodingSpecialCharsInFilePathName() {
41+
runAsDataHubDeveloper();
42+
new LoadHubModulesCommand(getHubConfig()).execute(newCommandContext());
43+
try {
44+
URLDecoder testDecoder = new URLDecoder();
45+
String data = testDecoder.decode("testURI/data/%23Name", StandardCharsets.UTF_8.name());
46+
assertEquals(data,"testURI/data/#Name");
47+
} catch (Exception e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)