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,21 +513,25 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
|
||||||
}
|
}
|
||||||
dm.walkDocument(property, path, indexes, context)
|
dm.walkDocument(property, path, indexes, context)
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
switch property := property.(type) {
|
if !propertyValue.IsNil() {
|
||||||
case encoding.TextMarshaler:
|
switch property := property.(type) {
|
||||||
txt, err := property.MarshalText()
|
case encoding.TextMarshaler:
|
||||||
if err == nil && subDocMapping != nil {
|
|
||||||
// index by explicit mapping
|
txt, err := property.MarshalText()
|
||||||
for _, fieldMapping := range subDocMapping.Fields {
|
if err == nil && subDocMapping != nil {
|
||||||
if fieldMapping.Type == "text" {
|
// index by explicit mapping
|
||||||
fieldMapping.processString(string(txt), pathString, path, indexes, context)
|
for _, fieldMapping := range subDocMapping.Fields {
|
||||||
|
if fieldMapping.Type == "text" {
|
||||||
|
fieldMapping.processString(string(txt), pathString, path, indexes, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
dm.walkDocument(property, path, indexes, context)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
default:
|
||||||
dm.walkDocument(property, path, indexes, context)
|
dm.walkDocument(property, path, indexes, context)
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
dm.walkDocument(property, path, indexes, context)
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
dm.walkDocument(property, path, indexes, context)
|
dm.walkDocument(property, path, indexes, context)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/blevesearch/bleve/analysis/tokenizer/exception"
|
"github.com/blevesearch/bleve/analysis/tokenizer/exception"
|
||||||
"github.com/blevesearch/bleve/analysis/tokenizer/regexp"
|
"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