Comments (6)
Hey @micimize! I'm so sorry I didn't see your reply back in May! I never got a notification from github that you replied! Your test cases were most helpful and I was able to fix the bug fairly quickly. I only wish I would have seen your reply a month ago so I could have fixed it then 😢
Anyway, I just released v4.0.2 with the fix. Let me know if you have any trouble with it.
By the way, doValidatePattern
is only called if all else fails. Everything in the loop above it will either return
or continue
the loop before reaching that point. So, it will only reach that if the pattern has been valid up until now, but a match could not be made, and neither **
or *
backtracking is possible. At that point, we already know we're returning false, we just want to know if we're also returning an error.
from doublestar.
will do! Sorry I haven't gotten around to actually testing it but will ping here if there are any issues when I do
from doublestar.
Hmm, are you using doublestar v4? What OS are you on? How are you building your pattern? You'll need to double the backslashes to get them to stay in the string, ie "**/log file \\{????-??-??\\}.txt"
.
I cannot reproduce this issue using v4 on macOS.
from doublestar.
I think I was maybe mistaken as to the exact issue – there is an issue with both \[
and \{
escaping.
If there is a match, they succeed, but if not, they return a syntax error. See https://play.golang.org/p/Saso864XooB
copied for reference
package main
import (
"fmt"
"github.com/bmatcuk/doublestar/v4"
)
func main() {
patterns := []string{
//`\{????-??-??\}.txt`,
//`\[????-??-??\].txt`,
`\{*\}.txt`,
`\[*\].txt`,
}
names := []string{
`{2021-05-01}.txt`,
`[2021-05-01].txt`,
`normal text`,
}
for _, p := range patterns {
for _, n := range names {
match, err := doublestar.Match(p, n)
fmt.Println(p, n, match, err)
}
}
}
/* output
\{*\}.txt {2021-05-01}.txt true <nil>
\{*\}.txt [2021-05-01].txt false syntax error in pattern
\{*\}.txt normal text false syntax error in pattern
\[*\].txt {2021-05-01}.txt false syntax error in pattern
\[*\].txt [2021-05-01].txt true <nil>
\[*\].txt normal text false syntax error in pattern
*/
from doublestar.
@bmatcuk I found the issue – every iteration of the loop consuming pattern validates the remaining pattern:
Lines 279 to 281 in 1fd2e2d
The default
fallthrough after '\\'
is matched breaks before bumping patIdx
when a match is rejected, resulting in an invalid pattern at validation time:
Lines 241 to 245 in 1fd2e2d
Why validate the pattern every loop? doValidatePattern
is called nameLen * patLen
times this way
from doublestar.
I'm going to close this issue since there hasn't been any activity. Let me know if you run into trouble with the fix!
from doublestar.
Related Issues (20)
- Ignore subdirectories pattern HOT 2
- Question: how to sponsor this project? HOT 4
- Does not match when **/ and {} are combined HOT 3
- Support fs.SkipDir HOT 4
- doublestar.FilepathGlob() should return filepath.ErrBadPattern, not path.ErrBadPattern HOT 3
- doublestar.FilepathGlob("..") returns nil. It should return []string{".."} HOT 1
- Glob sometimes hangs HOT 4
- `Glob` incorrectly returns errors if pattern does not match when failing on IO errors HOT 20
- PathMatch in v4 no longer working in Windows HOT 4
- Support for multiple nots HOT 3
- WithFilesOnly GlobOption - Returns matching files, but not matching directories HOT 3
- Question: double star path matching HOT 4
- [v1] TestMatch failure with go 1.20
- Feature request: add functionality to compile globs
- I want to match /xxx/xx/xx/acc.log.202302, it doesn't match /xxx/xx/xx/acc.isis.202302, should pass parameters HOT 1
- Support for extglob? HOT 3
- Globstar doesn't match zero directories HOT 4
- Support for character classes with quantifiers
- Allow skipping validation when `Match`ing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from doublestar.