Skip to content

Commit aaf8ce0

Browse files
authored
Fix exclude_type on non imported package (#3717)
1 parent f991090 commit aaf8ce0

File tree

4 files changed

+525
-2
lines changed

4 files changed

+525
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [Unreleased]
44

5-
- No changes yet.
5+
- Fix `exclude_type` on a non imported package.
66

77
## [v1.51.0] - 2025-03-28
88

private/bufpkg/bufimage/bufimageutil/bufimageutil_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func TestTypes(t *testing.T) {
101101
t.Parallel()
102102
runDiffTest(t, "testdata/options", "pkg.FooService.Do.exclude.txtar", WithExcludeTypes("pkg.FooService.Do"))
103103
})
104+
t.Run("exclude-package", func(t *testing.T) {
105+
t.Parallel()
106+
runDiffTest(t, "testdata/options", "pkg.Pkg.exclude.txtar", WithExcludeTypes("pkg"))
107+
})
104108
t.Run("exclude-all", func(t *testing.T) {
105109
t.Parallel()
106110
runDiffTest(t, "testdata/options", "all.exclude.txtar", WithExcludeTypes("pkg.Foo", "pkg.FooEnum", "pkg.FooService"))

private/bufpkg/bufimage/bufimageutil/image_filter.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ func filterImage(image bufimage.Image, options *imageFilterOptions) (bufimage.Im
5656
if file.IsImport() {
5757
continue
5858
}
59-
if err := closure.addElement(file.FileDescriptorProto(), "", false, imageIndex, options); err != nil {
59+
// Check if target package is filtered, this is not an error.
60+
// These includes are implicitly added to the closure.
61+
fileDescriptorProto := file.FileDescriptorProto()
62+
if mode := closure.elements[fileDescriptorProto]; mode == inclusionModeExcluded {
63+
continue
64+
}
65+
if err := closure.addElement(fileDescriptorProto, "", false, imageIndex, options); err != nil {
6066
return nil, err
6167
}
6268
}

0 commit comments

Comments
 (0)