mirror of
https://github.com/corda/corda.git
synced 2024-12-23 14:52:29 +00:00
Remove TODO associated with the fact that the ZIP filesystem does not specify the Path Separator character. Add a test to check access through forward or backward slashes is consistent.
This commit is contained in:
parent
2f4c0e9ae5
commit
63f40fd8d4
@ -381,12 +381,11 @@ interface Attachment : NamedByHash {
|
||||
* @throws FileNotFoundException if the given path doesn't exist in the attachment.
|
||||
*/
|
||||
fun extractFile(path: String, outputTo: OutputStream) {
|
||||
val p = path.toLowerCase()
|
||||
val p = path.toLowerCase().split('\\','/')
|
||||
openAsJAR().use { jar ->
|
||||
while (true) {
|
||||
val e = jar.nextJarEntry ?: break
|
||||
// TODO: Normalise path separators here for more platform independence, as zip doesn't mandate a type.
|
||||
if (e.name.toLowerCase() == p) {
|
||||
if (e.name.toLowerCase().split('\\','/') == p) {
|
||||
jar.copyTo(outputTo)
|
||||
return
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ class AttachmentsClassLoader(attachments: List<Attachment>, parent: ClassLoader
|
||||
// We already verified that paths are not strange/game playing when we inserted the attachment
|
||||
// into the storage service. So we don't need to repeat it here.
|
||||
//
|
||||
// We forbid files that differ only in case to avoid issues for Windows/Mac developers where the
|
||||
// We forbid files that differ only in case, or path separator to avoid issues for Windows/Mac developers where the
|
||||
// filesystem tries to be case insensitive. This may break developers who attempt to use ProGuard.
|
||||
//
|
||||
// TODO: Do we need extra overlap checks?
|
||||
val path = entry.name.toLowerCase()
|
||||
// Also convert to Unix path separators as all resource/class lookups will expect this.
|
||||
val path = entry.name.toLowerCase().replace('\\', '/')
|
||||
if (path in pathsToAttachments)
|
||||
throw OverlappingAttachments(path)
|
||||
pathsToAttachments[path] = attachment
|
||||
|
@ -9,6 +9,7 @@ import com.r3corda.core.serialization.*
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||
import com.r3corda.core.testing.MEGA_CORP
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
@ -93,6 +94,14 @@ class AttachmentClassLoaderTests {
|
||||
return bs.toByteArray()
|
||||
}
|
||||
|
||||
fun readAttachment(attachment: Attachment, filepath: String) : ByteArray {
|
||||
ByteArrayOutputStream().use {
|
||||
attachment.extractFile(filepath, it)
|
||||
return it.toByteArray()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test MockAttachmentStorage open as jar`() {
|
||||
val storage = MockAttachmentStorage()
|
||||
@ -130,6 +139,27 @@ class AttachmentClassLoaderTests {
|
||||
assertEquals("some data", txt)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Check platform independent path handling in attachment jars`() {
|
||||
val storage = MockAttachmentStorage()
|
||||
|
||||
val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("/folder1/foldera/file1.txt", "some data")))
|
||||
val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("\\folder1\\folderb\\file2.txt", "some other data")))
|
||||
|
||||
val data1a = readAttachment(storage.openAttachment(att1)!!, "/folder1/foldera/file1.txt")
|
||||
Assert.assertArrayEquals("some data".toByteArray(), data1a)
|
||||
|
||||
val data1b = readAttachment(storage.openAttachment(att1)!!, "\\folder1\\foldera\\file1.txt")
|
||||
Assert.assertArrayEquals("some data".toByteArray(), data1b)
|
||||
|
||||
val data2a = readAttachment(storage.openAttachment(att2)!!, "\\folder1\\folderb\\file2.txt")
|
||||
Assert.assertArrayEquals("some other data".toByteArray(), data2a)
|
||||
|
||||
val data2b = readAttachment(storage.openAttachment(att2)!!, "/folder1/folderb/file2.txt")
|
||||
Assert.assertArrayEquals("some other data".toByteArray(), data2b)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `loading class AnotherDummyContract`() {
|
||||
val storage = MockAttachmentStorage()
|
||||
|
Loading…
Reference in New Issue
Block a user