Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suffix * handling in our CODEOWNERS path matcher #5308

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public class CodeownersFileTests
new( "/a" , "*" , false , false ),
new( "/*" , "*" , true , false ),
new( "/*" , "a" , false , true ),
new( "/*" , "a/" , false , false ),
new( "/*" , "a/b" , false , false ),
new( "/*" , "a/" , false , true ),
new( "/*" , "a/b" , false , true ),
new( "/*" , "[" , false , true ),
new( "/*" , "]" , false , true ),
new( "/*" , "!" , false , true ),
Expand All @@ -94,6 +94,12 @@ public class CodeownersFileTests
new( "/**" , "[" , false , false ),
new( "/**" , "]" , false , false ),
new( "/**" , "!" , false , false ),
new( "/a*" , "a" , false , true ),
new( "/a*" , "a/x" , false , true ),
new( "/a*" , "a/x/d" , false , true ),
new( "/a*" , "ab" , false , true ),
new( "/a*" , "ab/x" , false , true ),
new( "/a*" , "ab/x/d" , false , true ),
new( "/a/**" , "a" , false , false ),
new( "/*/**" , "a" , false , false ),
new( "/*/**" , "a/" , false , false ),
Expand All @@ -108,8 +114,8 @@ public class CodeownersFileTests
new( "/a/*" , "a" , false , false ),
new( "/a/*" , "a/" , false , true ),
new( "/a/*" , "a/b" , false , true ),
new( "/a/*" , "a/b/" , false , false ),
new( "/a/*" , "a/b/c" , false , false ),
new( "/a/*" , "a/b/" , false , true ),
new( "/a/*" , "a/b/c" , false , true ),
new( "/a/*/" , "a" , false , false ),
new( "/a/*/" , "a/" , false , false ),
new( "/a/*/" , "a/b" , false , false ),
Expand Down Expand Up @@ -162,7 +168,7 @@ public class CodeownersFileTests
new( "**/*.md" , "a/b.md/x.md" , false , false ),
new( "/*.md" , "a/md" , false , false ),
new( "/a.*" , "a.b" , false , true ),
new( "/a.*" , "a.b/" , false , false ),
new( "/a.*" , "a.b/" , false , true ),
new( "/a.*" , "x/a.b/" , false , false ),
new( "/a.*/" , "a.b" , false , false ),
new( "/a.*/" , "a.b/" , false , true ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,16 @@ private static string SetPatternSuffix(string pattern)
// even though in such case the path might be a path to a directory.
if (!pattern.EndsWith("/"))
{
// Append "end of string" symbol, denoting the match has to be exact,
// not a substring, as we are dealing with a file.
pattern += "$";
// Manual experiments with how GitHub applies ownership show
// that a path like "/foo*" is effectively equivalent to
// "Match any path with prefix of '/foo'".
// Hence, we are not appending "$" if this is the case.
if (!pattern.EndsWith(SingleStar))
{
// Append "end of string" symbol, denoting the match has to be exact,
// not a substring, as we are dealing with a file.
pattern += "$";
}
}
else // The pattern ends with "/", denoting it is a directory.
{
Expand Down