File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,9 @@ func (f FS) lookup(name string) *file {
244
244
if name == "." {
245
245
return dotFile
246
246
}
247
+ if f .files == nil {
248
+ return nil
249
+ }
247
250
248
251
// Binary search to find where name would be in the list,
249
252
// and then check if name is at that position.
@@ -261,6 +264,9 @@ func (f FS) lookup(name string) *file {
261
264
262
265
// readDir returns the list of files corresponding to the directory dir.
263
266
func (f FS ) readDir (dir string ) []file {
267
+ if f .files == nil {
268
+ return nil
269
+ }
264
270
// Binary search to find where dir starts and ends in the list
265
271
// and then return that slice of the list.
266
272
files := * f .files
Original file line number Diff line number Diff line change @@ -112,3 +112,20 @@ func TestHidden(t *testing.T) {
112
112
testDir (t , star , "testdata/.hidden" ,
113
113
"fortune.txt" , "more/" ) // but not .more or _more
114
114
}
115
+
116
+ func TestUninitialized (t * testing.T ) {
117
+ var uninitialized embed.FS
118
+ testDir (t , uninitialized , "." )
119
+ f , err := uninitialized .Open ("." )
120
+ if err != nil {
121
+ t .Fatal (err )
122
+ }
123
+ defer f .Close ()
124
+ fi , err := f .Stat ()
125
+ if err != nil {
126
+ t .Fatal (err )
127
+ }
128
+ if ! fi .IsDir () {
129
+ t .Errorf ("in uninitialized embed.FS, . is not a directory" )
130
+ }
131
+ }
You can’t perform that action at this time.
0 commit comments