Skip to content
Open
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 @@ -377,7 +377,12 @@ private StringBuilder addCustomParameters(Map<String, Property> paramsMap) {
}
StringBuilder customParameters = new StringBuilder("-p \"");
for (Map.Entry<String, Property> entry : paramsMap.entrySet()) {
customParameters.append(String.format(CUSTOM_PARAM, entry.getKey(), entry.getValue().getValue()));
String value = entry.getValue().getValue();
// Escape single quotes for shell safety: ' -> '\'' (bash standard escape)
// Prevents shell quoting conflicts when value contains single quotes, e.g.
// AND create_data > '2026-05-06 10:59:09' -> AND create_data > '\''2026-05-06 10:59:09'\''
String escapedValue = value == null ? "" : value.replace("'", "'\\''");
customParameters.append(String.format(CUSTOM_PARAM, entry.getKey(), escapedValue));
}
customParameters.replace(4, 5, "");
customParameters.append("\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ public void testHandleParamsMap() throws Exception {
"${PYTHON_LAUNCHER} ${DATAX_LAUNCHER} --jvm=\"-Xms1G -Xmx1G\" -p \"-DDT='DT' -DDS='DS'\" /tmp/execution/app-id_job.json");
}

@Test
public void testBuildCommandEscapesSingleQuotesInCustomParameters() {
Map<String, Property> paramsMap = new HashMap<>();
Property conditionProperty = new Property();
conditionProperty.setProp("ds_incr_condition");
conditionProperty.setDirect(Direct.IN);
conditionProperty.setType(DataType.VARCHAR);
conditionProperty.setValue("AND create_data > '2026-05-06 10:59:09'");
paramsMap.put("ds_incr_condition", conditionProperty);

String command = dataxTask.buildCommand("/tmp/execution/app-id_job.json", paramsMap);
Assertions.assertEquals(
"${PYTHON_LAUNCHER} ${DATAX_LAUNCHER} --jvm=\"-Xms1G -Xmx1G\" "
+ "-p \"-Dds_incr_condition='AND create_data > '\\''2026-05-06 10:59:09'\\'''\" "
+ "/tmp/execution/app-id_job.json",
command);
}

@Test
public void testHandleInterruptedException() throws Exception {
String parameters = JSONUtils.toJsonString(createDataxParameters());
Expand Down
Loading