Commit 9e4c3c54 authored by Rolf Krahl's avatar Rolf Krahl

Merge branch 'issue92'

parents 03c5c7d6 f93ce617
......@@ -711,7 +711,7 @@ public class IdsBean {
String location = dfInfo.getDfLocation();
try {
if ((long) reader
.search("SELECT COUNT(df) FROM Datafile df WHERE df.location LIKE '" + location + "%'")
.search("SELECT COUNT(df) FROM Datafile df WHERE df.location LIKE '" + location.replaceAll("'", "''") + "%'")
.get(0) == 0) {
if (mainStorage.exists(location)) {
logger.debug("Delete physical file " + location + " from main storage");
......
......@@ -170,36 +170,36 @@ public class Tidier {
}
}
private boolean addStringConstraint(StringBuilder sb, String var, String value, boolean andNeeded) {
if (value != null) {
if (andNeeded) {
sb.append(" AND ");
} else {
sb.append(" ");
andNeeded = true;
}
sb.append(var + " = '" + value + "'");
}
private final static Logger logger = LoggerFactory.getLogger(Tidier.class);
static boolean addStringConstraint(StringBuilder sb, String var, String value, boolean andNeeded) {
if (value != null) {
if (andNeeded) {
sb.append(" AND ");
} else {
sb.append(" ");
andNeeded = true;
}
return andNeeded;
sb.append(var + " = '" + value.replaceAll("'", "''") + "'");
}
return andNeeded;
}
private boolean addNumericConstraint(StringBuilder sb, String var, Long value, boolean andNeeded) {
if (value != null) {
if (andNeeded) {
sb.append(" AND ");
} else {
sb.append(" ");
andNeeded = true;
}
sb.append(var + " = " + value);
static boolean addNumericConstraint(StringBuilder sb, String var, Long value, boolean andNeeded) {
if (value != null) {
if (andNeeded) {
sb.append(" AND ");
} else {
sb.append(" ");
andNeeded = true;
}
return andNeeded;
sb.append(var + " = " + value);
}
return andNeeded;
}
private final static Logger logger = LoggerFactory.getLogger(Tidier.class);;
static void cleanPreparedDir(Path preparedDir, int preparedCount) throws IOException {
Map<Long, Path> dateMap = new HashMap<>();
......
......@@ -13,6 +13,8 @@
until IDS is restarted. (Issue #87)</li>
<li>Fix once again JMS Session not closed if an exception is thrown (Issue #85).
The previous fix from 1.9.0 was not thread safe.</li>
<li>Fix: must escape apostrophe character in datafile location values when
building JPQL queries (Issue #92).</li>
</ul>
<h2>1.9.0</h2>
......
......@@ -2,6 +2,7 @@ package org.icatproject.ids;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.nio.file.Files;
......@@ -82,4 +83,22 @@ public class TidierTest {
assertFalse(Files.exists(pf));
}
@Test
public void testAddStringConstraint() throws Exception {
StringBuilder sb1 = new StringBuilder();
boolean andNeeded = Tidier.addStringConstraint(sb1, "df.location", "/path/to/normal/file", false);
assertEquals(" df.location = '/path/to/normal/file'", sb1.toString());
/* Fix error where a file path contains an apostrophe */
StringBuilder sb2 = new StringBuilder();
andNeeded = Tidier.addStringConstraint(sb2, "df.location", "/path/to/Person's Files/myscript.py", false);
assertEquals(" df.location = '/path/to/Person''s Files/myscript.py'", sb2.toString());
}
@Test
public void testAddNumericConstraint() throws Exception {
StringBuilder sb3 = new StringBuilder();
boolean andNeeded = Tidier.addNumericConstraint(sb3, "df.id", 12345L, false);
assertEquals(" df.id = 12345", sb3.toString());
}
}
......@@ -293,7 +293,7 @@ public class BaseTest {
Datafile df4 = new Datafile();
df4.setName("df4_" + timestamp);
df4.setLocation(ds2Loc + UUID.randomUUID());
df4.setLocation(ds2Loc + "Person's file");
df4.setDataset(ds2);
writeToFile(df4, "df4 test content very compressible very compressible", key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment