Skip to content
Merged
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 @@ -128,7 +128,7 @@ public PerspectiveModel load(String persistenceKey) throws IOException, Persiste
}

protected void validatePerspectiveFile(File file) throws IOException {
File dir = file.getParentFile();
File dir = file.getAbsoluteFile().getParentFile();
if(!dir.exists()) {
dir.mkdirs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -91,7 +90,7 @@ public boolean store(OutputStream os, PerspectiveModel perspectiveModel) throws
transformer.setOutputProperty(OutputKeys.INDENT, "yes");

DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new OutputStreamWriter(os));
StreamResult result = new StreamResult(os);

transformer.transform(source, result);
} catch (TransformerConfigurationException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@ void testFailedFirstStoreLeavesNoFile(@TempDir File dir) {
assertEquals(0, dir.list().length);
}

@Test
void testRelativeFileWithoutDirectoryIsValid(@TempDir File dir) throws Exception {
FilePersistenceHandler handler = new FilePersistenceHandler(new File(dir, "default.xml"));

// Validated only: storing would write to the working directory
assertDoesNotThrow(() -> handler.validatePerspectiveFile(new File("relative.xml")));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.flexdock.perspective.persist.xml;

import org.flexdock.perspective.Perspective;
import org.flexdock.perspective.persist.PerspectiveModel;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import static org.junit.jupiter.api.Assertions.*;

class XMLPersisterTest {

private static final String E_ACUTE = String.valueOf((char) 0xE9);

// Fails without the fix only where the platform charset is not UTF-8, e.g. on
// Windows with -DargLine=-Dfile.encoding=COMPAT (JDK 18+ defaults to UTF-8)
@Test
void testNonAsciiNameSurvives() throws Exception {
String name = "Caf" + E_ACUTE;
Perspective perspective = new Perspective("one", name);
PerspectiveModel model = new PerspectiveModel("one", "one", new Perspective[] {perspective});
XMLPersister persister = XMLPersister.newDefaultInstance();
ByteArrayOutputStream os = new ByteArrayOutputStream();

persister.store(os, model);
PerspectiveModel result = persister.load(new ByteArrayInputStream(os.toByteArray()));

assertEquals(name, result.getPerspectives()[0].getName());
}

}
2 changes: 2 additions & 0 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Fixes:
is missing, instead of overflowing the stack
* UIFactory: create a custom theme under a look and feel without a theme mapping
* FloatingGroup: save and clone a floating group whose bounds were never set
* XMLPersister: write layout XML as UTF-8, as its header declares
* FilePersistenceHandler: save to a relative layout file without a directory

== flexdock 1.3 RELEASE NOTES ==

Expand Down
Loading