Skip to content

Commit

Permalink
Fix issues with spaces in paths
Browse files Browse the repository at this point in the history
Fixes #16 and
hopefully also #15.

Co-Authored-By: Alexander <[email protected]>

see #17
  • Loading branch information
bertfrees committed Jun 6, 2019
1 parent 6066381 commit ed2f8b0
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<settingsFile>src/it/settings.xml</settingsFile>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<!--
Note that this path contains a space, as does the path to the "test- standalone-jar" test.
-->
<localRepositoryPath>${project.build.directory}/local- repo</localRepositoryPath>
<properties>
<liblouis-java.version>${project.version}</liblouis-java.version>
<liblouis-java.basedir>${project.basedir}</liblouis-java.basedir>
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/main/java/org/liblouis/EmbeddedTableResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public URL resolve(String table, URL base) {
return aggregatorTables.get(table);
StringBuilder b = new StringBuilder();
for (String s : table.split(","))
b.append("include ").append(s.replaceAll("\\\\", "\\\\\\\\")).append('\n');
// replace "\" (file separator on Windows) with "\\" and " " (space in file path) with "\s"
b.append("include ").append(s.replaceAll("\\\\", "\\\\\\\\").replaceAll(" ", "\\\\s")).append('\n');
InputStream in = new ByteArrayInputStream(b.toString().getBytes(StandardCharsets.UTF_8));
try {
File f = File.createTempFile("liblouis-java-", ".tbl");
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/liblouis/Louis.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -352,7 +351,7 @@ static File asFile(URL url) throws IllegalArgumentException {
try {
if (!"file".equals(url.getProtocol()))
throw new RuntimeException("expected file URL");
return new File(new URI("file", url.getPath(), null));
return new File(url.toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e); // should not happen
}
Expand All @@ -362,7 +361,7 @@ static File asFile(URL url) throws IllegalArgumentException {
static URL asURL(File file) {
try {
file = file.getCanonicalFile();
return new URL(URLDecoder.decode(file.toURI().toString().replace("+", "%2B")));
return file.toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e); // should not happen
} catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/liblouis/FindTranslatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testListAvailableLocales() {
}

public FindTranslatorTest() {
File testRootDir = new File(this.getClass().getResource("/").getPath());
File testRootDir = asFile(this.getClass().getResource("/"));
final Set<String> tables = new HashSet<String>();
for (File f : new File(testRootDir, "tables").listFiles())
tables.add(f.getAbsolutePath());
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/liblouis/TableFromFileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;

import static org.liblouis.Louis.asFile;

public class TableFromFileSystemTest {

@Test
Expand All @@ -18,7 +20,7 @@ public void testTableFromFileSystemAbsolutePath() throws Exception {
private final File tablesDir;

public TableFromFileSystemTest() {
File testRootDir = new File(this.getClass().getResource("/").getPath());
File testRootDir = asFile(this.getClass().getResource("/"));
tablesDir = new File(testRootDir, "tables");
}
}
3 changes: 2 additions & 1 deletion src/test/java/org/liblouis/TableResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;

import static org.liblouis.Louis.asFile;
import static org.liblouis.Louis.asURL;

public class TableResolverTest {
Expand All @@ -29,7 +30,7 @@ public void testIncludeMagicTokenTable() throws Exception {
}

public TableResolverTest() {
final File testRootDir = new File(this.getClass().getResource("/").getPath());
final File testRootDir = asFile(this.getClass().getResource("/"));
Louis.setTableResolver(new TableResolver() {
public URL resolve(String table, URL base) {
if (table == null)
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/liblouis/ThreadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.junit.Test;

import static org.liblouis.Louis.asFile;

public class ThreadsTest {

// If liblouis-java is thread-safe, the test should finish without causing crashes.
Expand Down Expand Up @@ -51,7 +53,7 @@ private static String generateString(Random rng, String characters, int length)
private final File tablesDir;

public ThreadsTest() {
File testRootDir = new File(this.getClass().getResource("/").getPath());
File testRootDir = asFile(this.getClass().getResource("/"));
tablesDir = new File(testRootDir, "tables");
}
}
3 changes: 2 additions & 1 deletion src/test/java/org/liblouis/TranslatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.Test;

import org.liblouis.DisplayTable.StandardDisplayTables;
import static org.liblouis.Louis.asFile;
import static org.liblouis.Utilities.Hyphenation.insertHyphens;

public class TranslatorTest {
Expand Down Expand Up @@ -132,7 +133,7 @@ private int[] byteToInt(byte [] array) {
private final File tablesDir;

public TranslatorTest() {
File testRootDir = new File(this.getClass().getResource("/").getPath());
File testRootDir = asFile(this.getClass().getResource("/"));
tablesDir = new File(testRootDir, "tables");
}
}

0 comments on commit ed2f8b0

Please sign in to comment.