开发者

Spring's AntPathMatcher matching behavior with linux paths

I came across this weird behavior from AntPathMatcher, which I isolated in the unit test below:

@Test
    public void testAntPathMacherPotentiallyBrokenForNix() throws IOException {
        AntPathMatcher antPathMatcher = new AntPathMatcher();
        Resource resource = new ClassPathResource("properties/RESOURCE_TEST.properties"); // there's a RESOURCE_TEST.properties under a directory 'properties'
        String localPath = resource.getFile().getAbsolutePath();

        Assert.assertThat(antPathMatcher.match("*.properties", localPath), is(true));

        String nixPath = "/local/app/instances/properties/RESOURCE_TEST.properties";

        Assert.assertThat(antPathMatcher.match("*.properties", nixPath), is(true));
}

The 2nd assertion fails, but sho开发者_C百科uldn't both assertions above be true?

What am I missing? (not that I really must use AntPathMatcher, I'm just curious)


I tried to reproduce that, but in Spring 3, both versions fail (I'm not touching 2.5 ever again :-)).

Reason: you can't start a path with a wildcard, you need a root to anchor.

Use this pattern: /**/*.properties, and at least in Spring 3, both tests will succeed.


Try this:

antPathMatcher.setPathSeparator(System.getProperty("file.separator")) ;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜