fhoeben/hsac-fitnesse-fixtures

FileFixture set directory bonus directory when escaping

lennyg1 opened this issue · 1 comments

If I set a directory with set directory in fileFixture, and then escape the table with ! or ^, I get a different result than without.

The variant with escaping, gets another /files/ dir added to it.

Example;

|Import                       |
|nl.hsac.fitnesse.fixture.slim|

|script       |file fixture     |
|set directory|http://files/test|
|show         |get directory    |

^|script|
|set  directory|http://files/test|
|show          |get directory    |

It goes wrong in FileFixture :

    public void setDirectory(String aDirectory) {
        if (this.isFilesUrl(aDirectory)) {
            String url = this.getUrl(aDirectory);
            String relativeDir = url.substring("files".length());             <<<<< goes wrong for url: http://files/test
            relativeDir = relativeDir.replace('/', File.separatorChar);
            this.directory = this.filesDir + relativeDir;
        } else if ((new File(aDirectory)).isAbsolute()) {
            this.directory = aDirectory;
        } else {
            this.directory = (new File(this.getEnvironment().getFitNesseDir(), aDirectory)).getAbsolutePath();
        }

        if (!this.directory.endsWith(File.separator)) {
            this.directory = this.directory + File.separator;
        }

    }

Line

            String relativeDir = url.substring("files".length());

for url http://files/test should produce /test but it doesn't.

Replace

            String relativeDir = url.substring("files".length());

by

            String relativeDir = url.substring(url.indexOf("files") + "files".length());

I'll put in a pull request with the correction.