Skip to content

Commit

Permalink
Merge pull request #3354 from liquibase/fix-uriresource-resolve
Browse files Browse the repository at this point in the history
Fixed URIResource.resolveSibling
  • Loading branch information
nvoxland committed Oct 12, 2022
2 parents a244353 + 40530c0 commit 00ee3f9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Expand Up @@ -25,7 +25,7 @@ public Resource resolve(String other) {

@Override
public Resource resolveSibling(String other) {
return new URIResource(resolveSiblingPath(other), URI.create(getUri().toString().replaceFirst("/.*?$", "") + "/" + other));
return new URIResource(resolveSiblingPath(other), URI.create(getUri().toString().replaceFirst("/[^/]*$", "") + "/" + other));
}

@Override
Expand Down
Expand Up @@ -4,10 +4,10 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.nio.file.*;
import java.util.Collections;
import java.util.List;

public class ZipResourceAccessor extends AbstractPathResourceAccessor {

Expand Down Expand Up @@ -64,4 +64,8 @@ protected Resource createResource(Path file, String pathToAdd) {
return new PathResource(pathToAdd, file);
}

@Override
public List<String> describeLocations() {
return Collections.singletonList(fileSystem.toString());
}
}
@@ -1,10 +1,23 @@
package liquibase.resource

import spock.lang.Specification
import spock.lang.Unroll

class URIResourceAccessorTest extends Specification {

// "file:/c:/" | "file:/c:/"
// "http://example.local/nowhere.txt" | "http://example.local/nowhere.txt"
@Unroll
def resolveSibling() {
when:
def newResource = new URIResource(path, URI.create(uri)).resolveSibling(input)

then:
newResource.uri.toString() == expectedUri
newResource.path == expectedPath

where:
path | uri | input | expectedUri | expectedPath
"my/file.xml" | "file:/local/my/file.xml" | "other.csv" | "file:/local/my/other.csv" | "my/other.csv"
"liquibase/harness/data/changelogs/loadData.xml" | "jar:file:/C:/Users/example/liquibase-test-harness-1.0.6.jar!/liquibase/harness/data/changelogs/loadData.xml" | "load.csv" | "jar:file:/C:/Users/example/liquibase-test-harness-1.0.6.jar!/liquibase/harness/data/changelogs/load.csv" | "liquibase/harness/data/changelogs/load.csv"
"my/file.xml" | "http:/local/my/file.xml" | "other.csv" | "http:/local/my/other.csv" | "my/other.csv"
}
}
Expand Up @@ -69,4 +69,10 @@ class ZipResourceAccessorTest extends Specification {
]
}

def describeLocations() {
expect:
simpleTestAccessor.describeLocations().size() == 1
simpleTestAccessor.describeLocations()[0].replace("\\", "/").endsWith("target/test-classes/simple-files.jar")
}

}

0 comments on commit 00ee3f9

Please sign in to comment.