Merge pull request #605 from mschoch/fix-nil-ptr
fix nil ptr panic on newly introduced text marshaler support
This commit is contained in:
commit
9234339472
|
@ -513,8 +513,10 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
|
|||
}
|
||||
dm.walkDocument(property, path, indexes, context)
|
||||
case reflect.Ptr:
|
||||
if !propertyValue.IsNil() {
|
||||
switch property := property.(type) {
|
||||
case encoding.TextMarshaler:
|
||||
|
||||
txt, err := property.MarshalText()
|
||||
if err == nil && subDocMapping != nil {
|
||||
// index by explicit mapping
|
||||
|
@ -526,9 +528,11 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
|
|||
} else {
|
||||
dm.walkDocument(property, path, indexes, context)
|
||||
}
|
||||
|
||||
default:
|
||||
dm.walkDocument(property, path, indexes, context)
|
||||
}
|
||||
}
|
||||
default:
|
||||
dm.walkDocument(property, path, indexes, context)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve/analysis/tokenizer/exception"
|
||||
"github.com/blevesearch/bleve/analysis/tokenizer/regexp"
|
||||
|
@ -966,3 +967,27 @@ func TestMappingForTextMarshaler(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMappingForNilTextMarshaler(t *testing.T) {
|
||||
tm := struct {
|
||||
Marshalable *time.Time
|
||||
}{
|
||||
Marshalable: nil,
|
||||
}
|
||||
|
||||
// now verify that when a mapping explicity
|
||||
m := NewIndexMapping()
|
||||
txt := NewTextFieldMapping()
|
||||
m.DefaultMapping.AddFieldMappingsAt("Marshalable", txt)
|
||||
doc := document.NewDocument("x")
|
||||
err := m.MapDocument(doc, tm)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(doc.Fields) != 0 {
|
||||
t.Fatalf("expected 1 field, got: %d", len(doc.Fields))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user