Fix incorrect anchoring at start of string
re.search will find substrings unless we anchor. I think all gitignore rules should be anchored but I'm not 100% sure (hard to tell without test coverage).
Another solution could be to replace .search with .match but I don't see any obvious difference in behavior.
Fixes #10
@vlovich I saw tests were added 9 days ago - it would be great if you could add a test that covers this case :+1:
@mherrmann once #15 is merged the test suite will be run on PR's to ensure they pass.
@vlovich Can you resolve conflicts?
There has been a deprecation that requires that flags be at the front of the regular expression. I don't think this is directly related to this issue; however the deprecation warning comes up when anchoring. The following change fixes this warning:
https://github.com/mherrmann/gitignore_parser/blob/1710b2374eb984459be7a948f7a44d151f96a4b3/gitignore_parser.py#L107
regex = regex[:5] + '^' + regex[5:]
This changes strings from being ^(?ms)<something> to (?ms)^\something
@Javagedes It won't do anything. ^ can appear anywhere in the RE. The bug, however, affects only non-anchored matches.
Also, re.search in this application is like 100% slower than re.match() so I suggest to switch to latter. Check how I fixed it: https://github.com/excitoon/gitignorefile/blob/master/gitignorefile/init.py#L292
This exact regexp, BTW is 5-10% faster than which pathspec uses currently, I think it is best possible.
Also @mherrmann, you don't need these flags at all, they only generate warnings #30 and don't do anything useful. If you like them, consider adding them as re.M | re.S in the last argument to re.match()/re.search().
The deprecation mentioned above is now a hard error in python 3.11. So this library is now totally broken on the latest python.
@boxed added this to matrix test the repo https://github.com/mherrmann/gitignore_parser/pull/40
Highlights the problem exactly :)
I'd be happy to merge a PR that fixes for Python 3.11.
Superseded by #58.