#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Make LibreOffice sandbox tests pass on Windows (#8287)
Anthony Stirling15dd16a63fb3
diff --git a/app/common/src/main/java/stirling/software/common/util/LibreOfficeSandboxPolicy.java b/app/common/src/main/java/stirling/software/common/util/LibreOfficeSandboxPolicy.javaindex a98ca65f1d..bb9ce73548 100644--- a/app/common/src/main/java/stirling/software/common/util/LibreOfficeSandboxPolicy.java+++ b/app/common/src/main/java/stirling/software/common/util/LibreOfficeSandboxPolicy.java@@ -1,5 +1,6 @@package stirling.software.common.util;+import java.io.File;import java.io.IOException;import java.net.URI;import java.nio.charset.StandardCharsets;@@ -31,6 +32,10 @@ import lombok.extern.slf4j.Slf4j;final class LibreOfficeSandboxPolicy {static final String IPC_PIPE_DIR = "/tmp";++ // lo-sandbox splits its lists on the path-list separator: ':' on Linux, the only place it runs.+ static final String LIST_SEPARATOR = File.pathSeparator;+private static final String IPC_PIPE_PREFIX = "OSL_PIPE_";private static final String USER_INSTALLATION_PREFIX = "-env:UserInstallation=";@@ -101,7 +106,9 @@ final class LibreOfficeSandboxPolicy {}Map<String, String> env = new LinkedHashMap<>();- env.put("STIRLING_LO_ALLOW_RW", profile + ":" + outDir + ":/dev");+ env.put(+ "STIRLING_LO_ALLOW_RW",+ String.join(LIST_SEPARATOR, profile.toString(), outDir.toString(), "/dev"));env.put("STIRLING_LO_ALLOW_SOCK", IPC_PIPE_DIR);env.put("STIRLING_LO_ALLOW_RO_EXTRA", join(inputs));env.put("HOME", profile.toString());@@ -248,13 +255,14 @@ final class LibreOfficeSandboxPolicy {}private static boolean listable(Path profile, Path outDir, List<Path> inputs) {- if (profile.toString().contains(":") || outDir.toString().contains(":")) {+ if (profile.toString().contains(LIST_SEPARATOR)+ || outDir.toString().contains(LIST_SEPARATOR)) {return false;}- return inputs.stream().noneMatch(p -> p.toString().contains(":"));+ return inputs.stream().noneMatch(p -> p.toString().contains(LIST_SEPARATOR));}private static String join(List<Path> paths) {- return String.join(":", paths.stream().map(Path::toString).toList());+ return String.join(LIST_SEPARATOR, paths.stream().map(Path::toString).toList());}}diff --git a/app/common/src/test/java/stirling/software/common/util/LibreOfficeSandboxPolicyTest.java b/app/common/src/test/java/stirling/software/common/util/LibreOfficeSandboxPolicyTest.javaindex 41114c1271..d9196d7fb3 100644--- a/app/common/src/test/java/stirling/software/common/util/LibreOfficeSandboxPolicyTest.java+++ b/app/common/src/test/java/stirling/software/common/util/LibreOfficeSandboxPolicyTest.java@@ -8,6 +8,7 @@ import java.net.UnixDomainSocketAddress;import java.nio.channels.ServerSocketChannel;import java.nio.file.Files;import java.nio.file.Path;+import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.Optional;@@ -52,7 +53,8 @@ class LibreOfficeSandboxPolicyTest {assertEquals(profile, policy.profile());- assertEquals(profile + ":" + outDir + ":/dev", env.get("STIRLING_LO_ALLOW_RW"));+ String sep = LibreOfficeSandboxPolicy.LIST_SEPARATOR;+ assertEquals(profile + sep + outDir + sep + "/dev", env.get("STIRLING_LO_ALLOW_RW"));assertEquals(input.toString(), env.get("STIRLING_LO_ALLOW_RO_EXTRA"));assertEquals("/tmp", env.get("STIRLING_LO_ALLOW_SOCK"));assertEquals(profile.toString(), env.get("HOME"));@@ -63,6 +65,23 @@ class LibreOfficeSandboxPolicyTest {assertTrue(Files.isDirectory(outDir));}+ @Test+ @EnabledOnOs(OS.LINUX)+ void listsUseTheColonSeparatorLoSandboxParses() throws IOException {+ Path profile = tmp.resolve("p");+ Path outDir = tmp.resolve("o");+ Path a = Files.writeString(tmp.resolve("a.docx"), "x");+ Path b = Files.writeString(tmp.resolve("b.docx"), "x");+ List<String> command = new ArrayList<>(sofficeCommand(profile, outDir, a));+ command.add(b.toString());++ Map<String, String> env =+ LibreOfficeSandboxPolicy.forCommand(command, roots()).orElseThrow().env();++ assertEquals(profile + ":" + outDir + ":/dev", env.get("STIRLING_LO_ALLOW_RW"));+ assertEquals(a + ":" + b, env.get("STIRLING_LO_ALLOW_RO_EXTRA"));+ }+@Testvoid convertToFilterValueIsNotTreatedAsInput() throws IOException {Path input = Files.writeString(tmp.resolve("in.pdf"), "x");@@ -117,7 +136,9 @@ class LibreOfficeSandboxPolicyTest {@Testvoid pathWithListSeparatorIsLeftToSharedPolicy() throws IOException {- Path odd = Files.createDirectories(tmp.resolve("a:b"));+ Path odd =+ Files.createDirectories(+ tmp.resolve("a" + LibreOfficeSandboxPolicy.LIST_SEPARATOR + "b"));Path input = Files.writeString(tmp.resolve("in.docx"), "x");assertEquals(