-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle __MACOSX directories in zip files
- Loading branch information
1 parent
ec9a2d9
commit e066f98
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package shapefile | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func isMacOSXPath(p string) bool { | ||
dir, _ := filepath.Split(p) | ||
pathElements := strings.Split(dir, string(filepath.Separator)) | ||
for _, elem := range pathElements { | ||
if elem == "__MACOSX" { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package shapefile | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
) | ||
|
||
func TestIsMACOSX(t *testing.T) { | ||
type testCase struct { | ||
path string | ||
expected bool | ||
} | ||
testCases := []testCase{ | ||
{"__MACOSX/dir/._test.shp", true}, | ||
{"dir/__MACOSX/._test.shp", true}, | ||
{"dir/__MACOSX/dir/._test.shp", true}, | ||
{"dir/__MACOSX/dir/__MACOSX/._test.shp", true}, | ||
{"dir/._test.shp", false}, | ||
{"dir/ABC__MACOSX", false}, | ||
{"dir/ABC__MACOSX/._test.shp", false}, | ||
{"dir/._test.shp.__MACOSX", false}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.path, func(t *testing.T) { | ||
assert.Equal(t, tc.expected, isMacOSXPath(tc.path)) | ||
}) | ||
} | ||
} |