Skip to content

Commit 9b16ad0

Browse files
authored
Merge pull request #540 from wiiitek/issue-382
Issue 382: Build Fails on path with space
2 parents e007ec8 + 048fc0c commit 9b16ad0

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

src/main/java/org/owasp/esapi/reference/DefaultSecurityConfiguration.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.FileNotFoundException;
2121
import java.io.IOException;
2222
import java.io.InputStream;
23+
import java.net.URISyntaxException;
2324
import java.net.URL;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
@@ -581,13 +582,17 @@ public File getResourceFile(String filename) {
581582
}
582583

583584
if (fileUrl != null) {
584-
String fileLocation = fileUrl.getFile();
585-
f = new File(fileLocation);
586-
if (f.exists()) {
587-
logSpecial("Found in SystemResource Directory/resourceDirectory: " + f.getAbsolutePath());
588-
return f;
589-
} else {
590-
logSpecial("Not found in SystemResource Directory/resourceDirectory (this should never happen): " + f.getAbsolutePath());
585+
try {
586+
String fileLocation = fileUrl.toURI().getPath();
587+
f = new File(fileLocation);
588+
if (f.exists()) {
589+
logSpecial("Found in SystemResource Directory/resourceDirectory: " + f.getAbsolutePath());
590+
return f;
591+
} else {
592+
logSpecial("Not found in SystemResource Directory/resourceDirectory (this should never happen): " + f.getAbsolutePath());
593+
}
594+
} catch (URISyntaxException e) {
595+
logSpecial("Error while converting URL " + fileUrl + " to file path: " + e.getMessage());
591596
}
592597
} else {
593598
logSpecial("Not found in SystemResource Directory/resourceDirectory: " + resourceDirectory + File.separator + filename);

src/test/java/org/owasp/esapi/crypto/CryptoTokenTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ public final void testAddandGetAttributes() {
391391
private static void nap(int n) {
392392
try {
393393
System.out.println("Sleeping " + n + " seconds...");
394-
Thread.sleep( n * 1000 );
394+
// adds additional time to make sure we sleep more than n seconds
395+
int additionalTimeToSleep = 100;
396+
Thread.sleep( n * 1000 + additionalTimeToSleep );
395397
} catch (InterruptedException e) {
396398
; // Ignore
397399
}

src/test/java/org/owasp/esapi/reference/ExtensiveEncoderURITest.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import static org.junit.Assert.assertEquals;
44

5-
import java.io.File;
5+
import java.io.BufferedReader;
6+
import java.io.IOException;
7+
import java.io.InputStreamReader;
68
import java.net.URL;
79
import java.nio.charset.StandardCharsets;
8-
import java.nio.file.Files;
910
import java.util.ArrayList;
1011
import java.util.Collection;
1112
import java.util.List;
@@ -20,7 +21,7 @@
2021

2122
@RunWith(Parameterized.class)
2223
public class ExtensiveEncoderURITest {
23-
static List<String> inputs = new ArrayList<String>();
24+
static List<String> inputs = new ArrayList<>();
2425
Validator v = ESAPI.validator();
2526
String uri;
2627
boolean expected;
@@ -34,16 +35,24 @@ public ExtensiveEncoderURITest(String uri){
3435
@Parameters
3536
public static Collection<String> getMyUris() throws Exception{
3637
URL url = ExtensiveEncoderURITest.class.getResource("/urisForTest.txt");
37-
String fileName = url.getFile();
38-
File urisForText = new File(fileName);
39-
40-
inputs = Files.readAllLines(urisForText.toPath(), StandardCharsets.UTF_8);
41-
38+
39+
try( BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) ) {
40+
inputs = readAllLines(br);
41+
}
4242
return inputs;
4343
}
44-
44+
45+
private static List<String> readAllLines(BufferedReader br) throws IOException {
46+
List<String> lines = new ArrayList<>();
47+
String line;
48+
while ((line = br.readLine()) != null) {
49+
lines.add(line);
50+
}
51+
return lines;
52+
}
53+
4554
@Test
46-
public void testUrlsFromFile() throws Exception{
55+
public void testUrlsFromFile() {
4756
assertEquals(this.expected, v.isValidURI("URL", uri, false));
4857
}
4958

0 commit comments

Comments
 (0)