Merged from tip.
diff --git a/apic.go b/apic.go index ded1b99..29be91d 100644 --- a/apic.go +++ b/apic.go
@@ -83,10 +83,10 @@ // Create a new emitter object. func yaml_emitter_initialize(emitter *yaml_emitter_t) bool { *emitter = yaml_emitter_t{ - buffer: make([]byte, output_buffer_size), - raw_buffer: make([]byte, 0, output_raw_buffer_size), - states: make([]yaml_emitter_state_t, 0, initial_stack_size), - events: make([]yaml_event_t, 0, initial_queue_size), + buffer: make([]byte, output_buffer_size), + raw_buffer: make([]byte, 0, output_raw_buffer_size), + states: make([]yaml_emitter_state_t, 0, initial_stack_size), + events: make([]yaml_event_t, 0, initial_queue_size), } return true }
diff --git a/decode_test.go b/decode_test.go index 718b679..9b71562 100644 --- a/decode_test.go +++ b/decode_test.go
@@ -300,7 +300,7 @@ &struct{ B []int }{[]int{1, 2}}, }, - // BUG #1133337 + // Bug #1133337 { "foo: ''", map[string]*string{"foo": new(string)}, @@ -318,6 +318,21 @@ }{1, 0}, }, + // Bug #1191981 + { + "" + + "%YAML 1.1\n" + + "--- !!str\n" + + `"Generic line break (no glyph)\n\` + "\n" + + ` Generic line break (glyphed)\n\` + "\n" + + ` Line separator\u2028\` + "\n" + + ` Paragraph separator\u2029"` + "\n", + "" + + "Generic line break (no glyph)\n" + + "Generic line break (glyphed)\n" + + "Line separator\u2028Paragraph separator\u2029", + }, + // Struct inlining { "a: 1\nb: 2\nc: 3\n", @@ -341,16 +356,25 @@ for i, item := range unmarshalTests { t := reflect.ValueOf(item.value).Type() var value interface{} - if t.Kind() == reflect.Map { + switch t.Kind() { + case reflect.Map: value = reflect.MakeMap(t).Interface() - } else { + case reflect.String: + t := reflect.ValueOf(item.value).Type() + v := reflect.New(t) + value = v.Interface() + default: pt := reflect.ValueOf(item.value).Type() pv := reflect.New(pt.Elem()) value = pv.Interface() } err := goyaml.Unmarshal([]byte(item.data), value) c.Assert(err, IsNil, Commentf("Item #%d", i)) - c.Assert(value, DeepEquals, item.value) + if t.Kind() == reflect.String { + c.Assert(*value.(*string), Equals, item.value, Commentf("Item #%d", i)) + } else { + c.Assert(value, DeepEquals, item.value, Commentf("Item #%d", i)) + } } }
diff --git a/scannerc.go b/scannerc.go index daad349..943a597 100644 --- a/scannerc.go +++ b/scannerc.go
@@ -2520,7 +2520,7 @@ // Join the whitespaces or fold line breaks. if leading_blanks { // Do we need to fold line breaks? - if leading_break[0] == '\n' { + if len(leading_break) > 0 && leading_break[0] == '\n' { if len(trailing_breaks) == 0 { s = append(s, ' ') } else {
diff --git a/yamlprivateh.go b/yamlprivateh.go index fd8414b..1c0b23d 100644 --- a/yamlprivateh.go +++ b/yamlprivateh.go
@@ -114,8 +114,8 @@ // Check if the character is a line break or NUL. func is_breakz(b []byte, i int) bool { //return is_break(b, i) || is_z(b, i) - return (// is_break: - b[i] == '\r' || // CR (#xD) + return ( // is_break: + b[i] == '\r' || // CR (#xD) b[i] == '\n' || // LF (#xA) b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) @@ -127,8 +127,8 @@ // Check if the character is a line break, space, or NUL. func is_spacez(b []byte, i int) bool { //return is_space(b, i) || is_breakz(b, i) - return (// is_space: - b[i] == ' ' || + return ( // is_space: + b[i] == ' ' || // is_breakz: b[i] == '\r' || // CR (#xD) b[i] == '\n' || // LF (#xA) @@ -141,8 +141,8 @@ // Check if the character is a line break, space, tab, or NUL. func is_blankz(b []byte, i int) bool { //return is_blank(b, i) || is_breakz(b, i) - return (// is_blank: - b[i] == ' ' || b[i] == '\t' || + return ( // is_blank: + b[i] == ' ' || b[i] == '\t' || // is_breakz: b[i] == '\r' || // CR (#xD) b[i] == '\n' || // LF (#xA)