Merge lp:~niemeyer/goyaml/fix-1191981 into lp:goyaml

Proposed by Gustavo Niemeyer
Status: Merged
Merged at revision: 45
Proposed branch: lp:~niemeyer/goyaml/fix-1191981
Merge into: lp:goyaml
Diff against target: 131 lines (+39/-15)
4 files modified
apic.go (+4/-4)
decode_test.go (+28/-4)
scannerc.go (+1/-1)
yamlprivateh.go (+6/-6)
To merge this branch: bzr merge lp:~niemeyer/goyaml/fix-1191981
Reviewer Review Type Date Requested Status
goyaml maintainers Pending
Review via email: mp+170372@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :
Download full text (4.8 KiB)

Reviewers: mp+170372_code.launchpad.net,

Message:
Please take a look.

Description:
Test and fix bug #1191981.

https://code.launchpad.net/~niemeyer/goyaml/fix-1191981/+merge/170372

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/10417043/

Affected files:
   A [revision details]
   M apic.go
   M decode_test.go
   M scannerc.go
   M yamlprivateh.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: apic.go
=== modified file 'apic.go'
--- apic.go 2013-04-30 18:59:24 +0000
+++ apic.go 2013-06-19 14:22:59 +0000
@@ -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
  }

Index: decode_test.go
=== modified file 'decode_test.go'
--- decode_test.go 2013-05-29 17:23:20 +0000
+++ decode_test.go 2013-06-19 14:22:34 +0000
@@ -300,7 +300,7 @@
    &struct{ B []int }{[]int{1, 2}},
   },

- // BUG #1133337
+ // Bug #1133337
   {
    "foo: ''",
    map[string]*string{"foo": new(string)},
@@ -317,22 +317,46 @@
     B int "-"
    }{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",
+ },
  }

  func (s *S) TestUnmarshal(c *C) {
   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))
+ }
   }
  }

Index: scannerc.go
=== modified file 'scannerc.go'
--- sc...

Read more...

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :
Revision history for this message
Roger Peppe (rogpeppe) wrote :

https://codereview.appspot.com/10417043/diff/3001/yamlprivateh.go
File yamlprivateh.go (right):

https://codereview.appspot.com/10417043/diff/3001/yamlprivateh.go#newcode117
yamlprivateh.go:117: return ( // is_break:
how about changing all of these to omit the brackets?

return b[i] == '\r' ||
    etc

https://codereview.appspot.com/10417043/

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

On 2013/06/19 14:57:59, rog wrote:
> https://codereview.appspot.com/10417043/diff/3001/yamlprivateh.go
> File yamlprivateh.go (right):

https://codereview.appspot.com/10417043/diff/3001/yamlprivateh.go#newcode117
> yamlprivateh.go:117: return ( // is_break:
> how about changing all of these to omit the brackets?

> return b[i] == '\r' ||
> etc

That's unrelated to this fix. I've just run go fmt.

https://codereview.appspot.com/10417043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apic.go'
2--- apic.go 2013-04-30 18:59:24 +0000
3+++ apic.go 2013-06-19 14:26:30 +0000
4@@ -83,10 +83,10 @@
5 // Create a new emitter object.
6 func yaml_emitter_initialize(emitter *yaml_emitter_t) bool {
7 *emitter = yaml_emitter_t{
8- buffer: make([]byte, output_buffer_size),
9- raw_buffer: make([]byte, 0, output_raw_buffer_size),
10- states: make([]yaml_emitter_state_t, 0, initial_stack_size),
11- events: make([]yaml_event_t, 0, initial_queue_size),
12+ buffer: make([]byte, output_buffer_size),
13+ raw_buffer: make([]byte, 0, output_raw_buffer_size),
14+ states: make([]yaml_emitter_state_t, 0, initial_stack_size),
15+ events: make([]yaml_event_t, 0, initial_queue_size),
16 }
17 return true
18 }
19
20=== modified file 'decode_test.go'
21--- decode_test.go 2013-05-29 17:23:20 +0000
22+++ decode_test.go 2013-06-19 14:26:30 +0000
23@@ -300,7 +300,7 @@
24 &struct{ B []int }{[]int{1, 2}},
25 },
26
27- // BUG #1133337
28+ // Bug #1133337
29 {
30 "foo: ''",
31 map[string]*string{"foo": new(string)},
32@@ -317,22 +317,46 @@
33 B int "-"
34 }{1, 0},
35 },
36+
37+ // Bug #1191981
38+ {
39+ "" +
40+ "%YAML 1.1\n" +
41+ "--- !!str\n" +
42+ `"Generic line break (no glyph)\n\` + "\n" +
43+ ` Generic line break (glyphed)\n\` + "\n" +
44+ ` Line separator\u2028\` + "\n" +
45+ ` Paragraph separator\u2029"` + "\n",
46+ "" +
47+ "Generic line break (no glyph)\n" +
48+ "Generic line break (glyphed)\n" +
49+ "Line separator\u2028Paragraph separator\u2029",
50+ },
51 }
52
53 func (s *S) TestUnmarshal(c *C) {
54 for i, item := range unmarshalTests {
55 t := reflect.ValueOf(item.value).Type()
56 var value interface{}
57- if t.Kind() == reflect.Map {
58+ switch t.Kind() {
59+ case reflect.Map:
60 value = reflect.MakeMap(t).Interface()
61- } else {
62+ case reflect.String:
63+ t := reflect.ValueOf(item.value).Type()
64+ v := reflect.New(t)
65+ value = v.Interface()
66+ default:
67 pt := reflect.ValueOf(item.value).Type()
68 pv := reflect.New(pt.Elem())
69 value = pv.Interface()
70 }
71 err := goyaml.Unmarshal([]byte(item.data), value)
72 c.Assert(err, IsNil, Commentf("Item #%d", i))
73- c.Assert(value, DeepEquals, item.value)
74+ if t.Kind() == reflect.String {
75+ c.Assert(*value.(*string), Equals, item.value, Commentf("Item #%d", i))
76+ } else {
77+ c.Assert(value, DeepEquals, item.value, Commentf("Item #%d", i))
78+ }
79 }
80 }
81
82
83=== modified file 'scannerc.go'
84--- scannerc.go 2013-04-30 21:29:04 +0000
85+++ scannerc.go 2013-06-19 14:26:30 +0000
86@@ -2520,7 +2520,7 @@
87 // Join the whitespaces or fold line breaks.
88 if leading_blanks {
89 // Do we need to fold line breaks?
90- if leading_break[0] == '\n' {
91+ if len(leading_break) > 0 && leading_break[0] == '\n' {
92 if len(trailing_breaks) == 0 {
93 s = append(s, ' ')
94 } else {
95
96=== modified file 'yamlprivateh.go'
97--- yamlprivateh.go 2013-04-30 19:42:40 +0000
98+++ yamlprivateh.go 2013-06-19 14:26:30 +0000
99@@ -114,8 +114,8 @@
100 // Check if the character is a line break or NUL.
101 func is_breakz(b []byte, i int) bool {
102 //return is_break(b, i) || is_z(b, i)
103- return (// is_break:
104- b[i] == '\r' || // CR (#xD)
105+ return ( // is_break:
106+ b[i] == '\r' || // CR (#xD)
107 b[i] == '\n' || // LF (#xA)
108 b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
109 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
110@@ -127,8 +127,8 @@
111 // Check if the character is a line break, space, or NUL.
112 func is_spacez(b []byte, i int) bool {
113 //return is_space(b, i) || is_breakz(b, i)
114- return (// is_space:
115- b[i] == ' ' ||
116+ return ( // is_space:
117+ b[i] == ' ' ||
118 // is_breakz:
119 b[i] == '\r' || // CR (#xD)
120 b[i] == '\n' || // LF (#xA)
121@@ -141,8 +141,8 @@
122 // Check if the character is a line break, space, tab, or NUL.
123 func is_blankz(b []byte, i int) bool {
124 //return is_blank(b, i) || is_breakz(b, i)
125- return (// is_blank:
126- b[i] == ' ' || b[i] == '\t' ||
127+ return ( // is_blank:
128+ b[i] == ' ' || b[i] == '\t' ||
129 // is_breakz:
130 b[i] == '\r' || // CR (#xD)
131 b[i] == '\n' || // LF (#xA)

Subscribers

People subscribed via source and target branches