You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2021/06/10 15:39:00 UTC

[jira] [Resolved] (IO-739) RegexFileFilter matches on path instead of name

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

Gary D. Gregory resolved IO-739.
--------------------------------
    Fix Version/s: 2.10.0
       Resolution: Fixed

Please search Jira before creating duplicates. 

> RegexFileFilter matches on path instead of name
> -----------------------------------------------
>
>                 Key: IO-739
>                 URL: https://issues.apache.org/jira/browse/IO-739
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Filters
>    Affects Versions: 2.9.0
>            Reporter: Hugo Zwaal
>            Priority: Minor
>             Fix For: 2.10.0
>
>         Attachments: ListFilesRegexBug.java
>
>
> The new RegexFileFilter.accept(Path, BasicFileAttributes) uses the full path for matching. When this filter is used in combination with FileUtils.listFiles(File, IOFileFilter, IOFileFilter), then it will not match anything if a path separator is not part of the pattern.
> The following small program will list all files when used with version 2.8.0 and nothing when used with version 2.9.0:
> {color:#770055}import {color}{color:#339999}org.apache.commons.io.FileUtils{color};
> {color:#770055}import {color}{color:#339999}org.apache.commons.io.filefilter.{color}*;
> {color:#770055}import {color}{color:#339999}java.io.File{color};
> {color:#770055}import {color}{color:#339999}java.util.Collection{color};
> {color:#770055}class {color}{color:#339999}ListFilesRegexBug {color}{
>    {color:#770055}public static void {color}main({color:#339999}String{color}[] {color:#660088}args{color}) {
>      {color:#339999}RegexFileFilter {color}{color:#6688ff}filter {color}= {color:#770055}new {color}RegexFileFilter({color:#0000cc}"[^/{color}{color:#cc88ff}\\\\{color}{color:#0000cc}]+"{color});
>      {color:#339999}Collection{color}<{color:#339999}File{color}> {color:#6688ff}files {color}= {color:#339999}FileUtils{color}.{color:#575757}listFiles{color}({color:#770055}new {color}File({color:#0000cc}"."{color}), {color:#6688ff}filter{color}, {color:#339999}TrueFileFilter{color}.{color:#0000aa}TRUE{color});
>      {color:#770055}for {color}({color:#339999}File {color}{color:#6688ff}f {color}: {color:#6688ff}files{color}) {
>        {color:#339999}System{color}.{color:#0000aa}out{color}.println({color:#6688ff}f{color}.getAbsolutePath());
>      }
>    }
> }



--
This message was sent by Atlassian Jira
(v8.3.4#803005)