unmarshalling map into *string has odd behaviour

Bug #1133337 reported by Roger Peppe
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
goyaml
Fix Released
Undecided
Gustavo Niemeyer

Bug Description

The following program has this output:

    "foo: ''\n" -> map[string]string{"foo":""}
    "foo: ''\n" -> map[string]*string{}
    "foo: null\n" -> map[string]string{"foo":"null"}
    "foo: null\n" -> map[string]*string{"foo":(*string)(nil)}

Line 1 is as expected.
Line 2 is unexpected - why is the foo attribute disappearing?
Line 3 is unexpected - should an unquoted null really turn into the empty string?
Line 4 is as expected.

 package main
 import (
  "fmt"
  "launchpad.net/goyaml"
 )

 func main() {
  parse("foo: ''\n", make(map[string]string))
  parse("foo: ''\n", make(map[string]*string))
  parse("foo: null\n", make(map[string]string))
  parse("foo: null\n", make(map[string]*string))
 }

 func parse(s string, x interface{}) {
  fmt.Printf("%q ", s)
  err := goyaml.Unmarshal([]byte(s), x)
  if err != nil {
   fmt.Printf("-> error %v\n", err)
   return
  }
  fmt.Printf("-> %#v\n", x)
 }

Revision history for this message
Данило Шеган (danilo) wrote :

Fixed in r39 of lp:goyaml it seems.

Changed in goyaml:
assignee: nobody → Gustavo Niemeyer (niemeyer)
status: New → Fix Committed
Changed in goyaml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.