Skip to content

Commit

Permalink
Properly parse filenames of files stored without dot
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
kdomanski committed Jul 10, 2021
1 parent 0cfb534 commit 8676453
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Binary file modified fixtures/test.iso
Binary file not shown.
5 changes: 5 additions & 0 deletions image_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (f *File) Name() string {
// assume only only one '.'
splitFileIdentifier := strings.Split(fileIdentifier, ".")

// there's no dot in the name, thus no extension
if len(splitFileIdentifier) == 1 {
return splitFileIdentifier[0]
}

// extension is empty, return just the name without a dot
if len(splitFileIdentifier[1]) == 0 {
return splitFileIdentifier[0]
Expand Down
47 changes: 47 additions & 0 deletions regression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package iso9660

import (
"bytes"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

// Regresstion test for github.com/kdomanski/iso9660/issues/9
func TestRegressionNameWithoutDot(t *testing.T) {
var buf bytes.Buffer

//
// create image with a file without dot
//
w, err := NewWriter()
assert.NoError(t, err)
defer func() {
if cleanupErr := w.Cleanup(); cleanupErr != nil {
t.Fatalf("failed to cleanup writer: %v", cleanupErr)
}
}()

err = w.AddFile(strings.NewReader("hrh2309hr320h"), "NODOT")
assert.NoError(t, err)

err = w.WriteTo(&buf, "testvolume")
assert.NoError(t, err)

//
// no read it
//

image, err := OpenImage(bytes.NewReader(buf.Bytes()))
assert.NoError(t, err)

rootDir, err := image.RootDir()
assert.NoError(t, err)

children, err := rootDir.GetChildren()
assert.NoError(t, err)

nodotfile := children[0]
assert.Equal(t, "nodot", nodotfile.Name())
}

0 comments on commit 8676453

Please sign in to comment.