Skip to content

withFileFromClassPath fails when path to classpath resource contains spaces #263

Closed

Description

@lbialy

Hello,

How to replicate:

  1. create directory with spaces in path
mkdir ~/dir\ with\ spaces
  1. move some project using testcontainers-java to that directory
  2. put a file to copy into container in resources directory (touch src/test/resources/any_file in this example)
  3. use container loading files from class path, ie:
new GenericContainer(
        new ImageFromDockerfile()
                .withDockerfileFromBuilder(builder -> {
                        builder
                                .from("alpine:3.2")
                                .copy("any_file", "any_file")
                                .build(); 
                        })
                )
                .withFileFromClasspath("any_file", "any_file")
)

This will throw exception:

1 error
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image name from org.testcontainers.images.builder.ImageFromDockerfile@61ae0d43
Caused by: java.lang.RuntimeException: Can't get size from ~/dir%20with%20spaces/your-project/target/test-classes/any_file
Caused by: java.nio.file.NoSuchFileException: ~/dir%20with%20spaces/your-project/target/test-classes/any_file

Issue is related to urlencoded spaces in path (%20) when using

URL resource = ClasspathTrait.class.getClassLoader().getResource(resourcePath);
String resourceFilePath = new File(resource.getFile()).getAbsolutePath();

in default implementation of withFileFromClasspath. Calling .toURI() instead of .getFile() on resource should fix this issue while not breaking anything - I'm using this workaround and seems to be fine. No PR though, sorry, simply no time to do it.

Activity

  1. rnorth commented on Jan 14, 2017

    @rnorth
    Member

    Hi @lbialy
    Thanks for reporting, and sorry for the problem and thorough analysis. We'll try and address soon.
    Richard

  2. self-assigned this
    on Jan 14, 2017
  3. lbialy commented on Jan 17, 2017

    @lbialy
    Author

    @rnorth I think you wanted to mention #262, not #263 here. Glad to see something found.

  4. modified the milestones: 1.1.8, 1.1.9 on Jan 22, 2017
  5. modified the milestones: 1.1.9, on Feb 12, 2017
  6. rnorth commented on Mar 13, 2017

    @rnorth
    Member

    @lbialy this is hopefully fixed now - please could you let me know if you encounter any more issues?

    I've been developing under a path containing space for a while, just to make sure 😃

  7. modified the milestones: 1.3.0, 1.2.0 on May 29, 2017
  8. bsideup commented on Jun 10, 2017

    @bsideup
    Member

    Hi @lbialy
    We released 1.3.0 with a few fixes to file mappings, could you please try it?
    Thanks!

  9. lbialy commented on Jun 14, 2017

    @lbialy
    Author

    I'll try, thanks!

  10. bsideup commented on Apr 11, 2018

    @bsideup
    Member

    Fixed by #279.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions