Merge pull request #13 from vearutop/json-unmarshaler

Strip comment from nextValue to fix custom unmarshalers
diff --git a/encoding/json5/decode.go b/encoding/json5/decode.go
index b7cd0ef..d31fc48 100644
--- a/encoding/json5/decode.go
+++ b/encoding/json5/decode.go
@@ -231,7 +231,6 @@
 		c := int(d.data[d.off])
 		d.off++
 		newOp = d.scan.step(&d.scan, c)
-		fmt.Println("c = ", string(c))
 		if newOp != scanSkipInComment {
 			break
 		}
diff --git a/encoding/json5/decode_test.go b/encoding/json5/decode_test.go
index 39b0eab..66adfab 100644
--- a/encoding/json5/decode_test.go
+++ b/encoding/json5/decode_test.go
@@ -7,6 +7,7 @@
 import (
 	"bytes"
 	"encoding"
+	"encoding/json"
 	"fmt"
 	"image"
 	"reflect"
@@ -1354,3 +1355,36 @@
 		}
 	}
 }
+
+type objectDecoder struct {
+	A int
+}
+
+func (o *objectDecoder) UnmarshalJSON(data []byte) error {
+	var v struct {
+		A int `json:"a"`
+	}
+
+	err := json.Unmarshal(data, &v)
+	if err != nil {
+		return err
+	}
+
+	o.A = v.A
+
+	return nil
+}
+
+func TestDecoder_Decode_Unmarshaler(t *testing.T) {
+	j5 := `{
+	// A.
+	"a": 123
+}`
+	var v objectDecoder
+
+	err := NewDecoder(bytes.NewBufferString(j5)).Decode(&v)
+
+	if err != nil {
+		t.Errorf("Unexpected error: %v", err)
+	}
+}
diff --git a/encoding/json5/scanner.go b/encoding/json5/scanner.go
index 1e445a9..3811e20 100644
--- a/encoding/json5/scanner.go
+++ b/encoding/json5/scanner.go
@@ -38,18 +38,27 @@
 	scan.reset()
 	for i, c := range data {
 		v := scan.step(scan, int(c))
+		if v == scanSkipInComment {
+			value = append(value, ' ')
+		} else {
+			value = append(value, data[i])
+		}
+
 		if v >= scanEnd {
 			switch v {
 			case scanError:
 				return nil, nil, scan.err
 			case scanEnd:
-				return data[0:i], data[i:], nil
+				return value[0 : len(value)-1], data[i:], nil
 			}
 		}
 	}
 	if scan.eof() == scanError {
 		return nil, nil, scan.err
 	}
+	if len(value) > 0 {
+		return value, nil, nil
+	}
 	return data, nil, nil
 }
 
@@ -711,7 +720,7 @@
 	}
 
 	// use quoted string with different quotation marks
-	s := strconv.Quote(string(c))
+	s := strconv.Quote(string(rune(c)))
 	return "'" + s[1:len(s)-1] + "'"
 }
 
diff --git a/encoding/json5/scanner_test.go b/encoding/json5/scanner_test.go
index a60afa3..44f4cd7 100644
--- a/encoding/json5/scanner_test.go
+++ b/encoding/json5/scanner_test.go
@@ -186,7 +186,7 @@
 	if err != nil {
 		t.Fatalf("nextValue: %s", err)
 	}
-	if len(item) != len(jsonBig) || &item[0] != &jsonBig[0] {
+	if len(item) != len(jsonBig) || item[0] != jsonBig[0] {
 		t.Errorf("invalid item: %d %d", len(item), len(jsonBig))
 	}
 	if len(rest) != 0 {