[ 
https://issues.apache.org/jira/browse/RAT-597?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Philipp Ottlinger updated RAT-597:
----------------------------------
    Fix Version/s: 0.19

> Directory-only .gitignore entries (trailing slash) never match
> --------------------------------------------------------------
>
>                 Key: RAT-597
>                 URL: https://issues.apache.org/jira/browse/RAT-597
>             Project: Apache RAT
>          Issue Type: Bug
>          Components: core engine
>            Reporter: Sylwester Lachiewicz
>            Priority: Major
>             Fix For: 0.19
>
>
> A {{.gitignore}} entry ending in a slash, such as {{build/}}, does not 
> exclude the directory it names.
> [GitIgnoreBuilder.java:139|https://github.com/apache/creadur-rat/blob/master/apache-rat-core/src/main/java/org/apache/rat/config/exclusion/fileprocessors/GitIgnoreBuilder.java#L139]
>  calls {{MatchPatterns.from(matcherPattern.localized(...))}} with one 
> {{String}}. That resolves to {{MatchPatterns.from(String separator, String... 
> sources)}}, so the pattern becomes the separator and the source list is 
> empty. A {{MatchPatterns}} with no patterns matches nothing, so 
> {{and(isDirectory, **/build)}} is always false and the entry has no effect.
> The existing {{GitIgnoreBuilderTest.modifyEntryTest}} only compares 
> {{toString()}} ({{not(and(isDirectory, **/filename))}}), which is built from 
> the name, not from the patterns, so it passes.
> Reproducer (JUnit 5, in {{org.apache.rat.config.exclusion.fileprocessors}}):
> {code:java}
> @TempDir Path tmp;
> @Test
> void directoryOnlyPatternExcludesDirectory() {
>     File base = tmp.toFile();
>     assertThat(new File(base, "build").mkdir()).isTrue();
>     DocumentName baseName = DocumentName.builder(base).build();
>     List<MatcherSet> sets = new ArrayList<>();
>     new GitIgnoreBuilder().modifyEntry(sets::add, baseName, "build/");
>     DocumentNameMatcher m = sets.get(0).createMatcher();
>     // excluded directory: the not(...) matcher must return false
>     assertThat(m.matches(baseName.resolve("build"))).isFalse();
> }
> {code}
> On master ({{060c14f}}) this fails: {{matches(build)}} is {{true}}.
> Fix: pass the separator explicitly.
> {code:java}
> MatchPatterns.from(documentName.getDirectorySeparator(),
>         matcherPattern.localized(documentName.getDirectorySeparator()))
> {code}
> With that change the reproducer and all 42 {{GitIgnoreBuilderTest}} cases 
> pass.
> The {{from(String separator, String... sources)}} overload in RAT's copy of 
> {{MatchPatterns}} makes this mistake easy to repeat; a signature that cannot 
> take a lone {{String}} would prevent it.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to