Skip to content

Commit 0886dc8

Browse files
Modified values.LiteralFname (if no name of file)
1 parent a1f2af1 commit 0886dc8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packet/values/literal.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ type LiteralFname string
3636

3737
//ToItem returns Item instance
3838
func (l LiteralFname) ToItem() *info.Item {
39+
name := string(l)
40+
if len(l) == 0 {
41+
name = "<null>"
42+
}
3943
return info.NewItem(
4044
info.Name("File name"),
41-
info.Value(string(l)),
45+
info.Value(name),
4246
)
4347
}
4448

packet/values/literal_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ func TestLiteralFname(t *testing.T) {
5555
}
5656
}
5757

58+
func TestLiteralFnameNil(t *testing.T) {
59+
i := LiteralFname("").ToItem()
60+
if i.Name != "File name" {
61+
t.Errorf("LiteralFname.Name = \"%s\", want \"File name\".", i.Name)
62+
}
63+
if i.Value != "<null>" {
64+
t.Errorf("LiteralFname.Value = \"%s\", want \"<null>\".", i.Value)
65+
}
66+
if i.Note != "" {
67+
t.Errorf("LiteralFname.Note = \"%s\", want \"\"", i.Note)
68+
}
69+
if i.Dump != "" {
70+
t.Errorf("LiteralFname.Dump = \"%s\", want \"\".", i.Dump)
71+
}
72+
}
73+
5874
func TestRawData(t *testing.T) {
5975
var data = []byte{0x01, 0x02, 0x03, 0x04}
6076
name := "Literal data"

0 commit comments

Comments
 (0)