diff --git a/src/restic/backend/id.go b/src/restic/backend/id.go index 6c7bc5321..115792707 100644 --- a/src/restic/backend/id.go +++ b/src/restic/backend/id.go @@ -44,7 +44,11 @@ func (id ID) String() string { const shortStr = 4 // Str returns the shortened string version of id. -func (id ID) Str() string { +func (id *ID) Str() string { + if id == nil { + return "[nil]" + } + if id.IsNull() { return "[null]" } diff --git a/src/restic/backend/id_int_test.go b/src/restic/backend/id_int_test.go index ed84a5a37..d46a1554b 100644 --- a/src/restic/backend/id_int_test.go +++ b/src/restic/backend/id_int_test.go @@ -8,4 +8,9 @@ func TestIDMethods(t *testing.T) { if id.Str() != "[null]" { t.Errorf("ID.Str() returned wrong value, want %v, got %v", "[null]", id.Str()) } + + var pid *ID + if pid.Str() != "[nil]" { + t.Errorf("ID.Str() returned wrong value, want %v, got %v", "[nil]", pid.Str()) + } }