psych 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -78,6 +78,7 @@ test/psych/test_stream.rb
78
78
  test/psych/test_string.rb
79
79
  test/psych/test_struct.rb
80
80
  test/psych/test_symbol.rb
81
+ test/psych/test_tainted.rb
81
82
  test/psych/test_to_yaml_properties.rb
82
83
  test/psych/test_tree_builder.rb
83
84
  test/psych/test_yaml.rb
data/ext/psych/parser.c CHANGED
@@ -73,6 +73,7 @@ static VALUE parse(VALUE self, VALUE yaml)
73
73
  yaml_parser_t * parser;
74
74
  yaml_event_t event;
75
75
  int done = 0;
76
+ int tainted = 0;
76
77
  #ifdef HAVE_RUBY_ENCODING_H
77
78
  int encoding = rb_utf8_encindex();
78
79
  rb_encoding * internal_enc = rb_default_internal_encoding();
@@ -81,8 +82,11 @@ static VALUE parse(VALUE self, VALUE yaml)
81
82
 
82
83
  Data_Get_Struct(self, yaml_parser_t, parser);
83
84
 
85
+ if (OBJ_TAINTED(yaml)) tainted = 1;
86
+
84
87
  if(rb_respond_to(yaml, id_read)) {
85
88
  yaml_parser_set_input(parser, io_reader, (void *)yaml);
89
+ if (RTEST(rb_obj_is_kind_of(yaml, rb_cIO))) tainted = 1;
86
90
  } else {
87
91
  StringValue(yaml);
88
92
  yaml_parser_set_input_string(
@@ -140,6 +144,7 @@ static VALUE parse(VALUE self, VALUE yaml)
140
144
  VALUE prefix = Qnil;
141
145
  if(start->handle) {
142
146
  handle = rb_str_new2((const char *)start->handle);
147
+ if (tainted) OBJ_TAINT(handle);
143
148
  #ifdef HAVE_RUBY_ENCODING_H
144
149
  PSYCH_TRANSCODE(handle, encoding, internal_enc);
145
150
  #endif
@@ -147,6 +152,7 @@ static VALUE parse(VALUE self, VALUE yaml)
147
152
 
148
153
  if(start->prefix) {
149
154
  prefix = rb_str_new2((const char *)start->prefix);
155
+ if (tainted) OBJ_TAINT(prefix);
150
156
  #ifdef HAVE_RUBY_ENCODING_H
151
157
  PSYCH_TRANSCODE(prefix, encoding, internal_enc);
152
158
  #endif
@@ -171,6 +177,7 @@ static VALUE parse(VALUE self, VALUE yaml)
171
177
  VALUE alias = Qnil;
172
178
  if(event.data.alias.anchor) {
173
179
  alias = rb_str_new2((const char *)event.data.alias.anchor);
180
+ if (tainted) OBJ_TAINT(alias);
174
181
  #ifdef HAVE_RUBY_ENCODING_H
175
182
  PSYCH_TRANSCODE(alias, encoding, internal_enc);
176
183
  #endif
@@ -188,6 +195,7 @@ static VALUE parse(VALUE self, VALUE yaml)
188
195
  (const char *)event.data.scalar.value,
189
196
  (long)event.data.scalar.length
190
197
  );
198
+ if (tainted) OBJ_TAINT(val);
191
199
 
192
200
  #ifdef HAVE_RUBY_ENCODING_H
193
201
  PSYCH_TRANSCODE(val, encoding, internal_enc);
@@ -195,6 +203,7 @@ static VALUE parse(VALUE self, VALUE yaml)
195
203
 
196
204
  if(event.data.scalar.anchor) {
197
205
  anchor = rb_str_new2((const char *)event.data.scalar.anchor);
206
+ if (tainted) OBJ_TAINT(anchor);
198
207
  #ifdef HAVE_RUBY_ENCODING_H
199
208
  PSYCH_TRANSCODE(anchor, encoding, internal_enc);
200
209
  #endif
@@ -202,6 +211,7 @@ static VALUE parse(VALUE self, VALUE yaml)
202
211
 
203
212
  if(event.data.scalar.tag) {
204
213
  tag = rb_str_new2((const char *)event.data.scalar.tag);
214
+ if (tainted) OBJ_TAINT(tag);
205
215
  #ifdef HAVE_RUBY_ENCODING_H
206
216
  PSYCH_TRANSCODE(tag, encoding, internal_enc);
207
217
  #endif
@@ -226,6 +236,7 @@ static VALUE parse(VALUE self, VALUE yaml)
226
236
  VALUE implicit, style;
227
237
  if(event.data.sequence_start.anchor) {
228
238
  anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
239
+ if (tainted) OBJ_TAINT(anchor);
229
240
  #ifdef HAVE_RUBY_ENCODING_H
230
241
  PSYCH_TRANSCODE(anchor, encoding, internal_enc);
231
242
  #endif
@@ -234,6 +245,7 @@ static VALUE parse(VALUE self, VALUE yaml)
234
245
  tag = Qnil;
235
246
  if(event.data.sequence_start.tag) {
236
247
  tag = rb_str_new2((const char *)event.data.sequence_start.tag);
248
+ if (tainted) OBJ_TAINT(tag);
237
249
  #ifdef HAVE_RUBY_ENCODING_H
238
250
  PSYCH_TRANSCODE(tag, encoding, internal_enc);
239
251
  #endif
@@ -258,6 +270,7 @@ static VALUE parse(VALUE self, VALUE yaml)
258
270
  VALUE implicit, style;
259
271
  if(event.data.mapping_start.anchor) {
260
272
  anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
273
+ if (tainted) OBJ_TAINT(anchor);
261
274
  #ifdef HAVE_RUBY_ENCODING_H
262
275
  PSYCH_TRANSCODE(anchor, encoding, internal_enc);
263
276
  #endif
@@ -265,6 +278,7 @@ static VALUE parse(VALUE self, VALUE yaml)
265
278
 
266
279
  if(event.data.mapping_start.tag) {
267
280
  tag = rb_str_new2((const char *)event.data.mapping_start.tag);
281
+ if (tainted) OBJ_TAINT(tag);
268
282
  #ifdef HAVE_RUBY_ENCODING_H
269
283
  PSYCH_TRANSCODE(tag, encoding, internal_enc);
270
284
  #endif
data/lib/psych.rb CHANGED
@@ -90,7 +90,7 @@ require 'psych/json'
90
90
 
91
91
  module Psych
92
92
  # The version is Psych you're using
93
- VERSION = '1.1.0'
93
+ VERSION = '1.1.1'
94
94
 
95
95
  # The version of libyaml Psych is using
96
96
  LIBYAML_VERSION = Psych.libyaml_version.join '.'
@@ -80,10 +80,10 @@ module Psych
80
80
  def parse_time string
81
81
  date, time = *(string.split(/[ tT]/, 2))
82
82
  (yy, m, dd) = date.split('-').map { |x| x.to_i }
83
- md = time.match(/(\d+:\d+:\d+)(\.\d*)?\s*(Z|[-+]\d+(:\d\d)?)?/)
83
+ md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)
84
84
 
85
85
  (hh, mm, ss) = md[1].split(':').map { |x| x.to_i }
86
- us = (md[2] ? Rational(md[2].sub(/^\./, '0.')) : 0) * 1000000
86
+ us = (md[2] ? Rational("0.#{md[2]}") : 0) * 1000000
87
87
 
88
88
  time = Time.utc(yy, m, dd, hh, mm, ss, us)
89
89
 
@@ -297,7 +297,7 @@ module Psych
297
297
  private
298
298
  def format_time time
299
299
  if time.utc?
300
- time.strftime("%Y-%m-%d %H:%M:%S.%9NZ")
300
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
301
301
  else
302
302
  time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
303
303
  end
@@ -95,7 +95,7 @@ module Psych
95
95
  time = Time.utc(2010, 10, 10)
96
96
  @stream.push({'a' => time })
97
97
  json = @io.string
98
- assert_match "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n", json
98
+ assert_match "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n", json
99
99
  end
100
100
 
101
101
  def test_datetime
@@ -53,7 +53,7 @@ module Psych
53
53
 
54
54
  def test_time
55
55
  time = Time.utc(2010, 10, 10)
56
- assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n",
56
+ assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n",
57
57
  Psych.to_json({'a' => time })
58
58
  end
59
59
 
@@ -0,0 +1,128 @@
1
+ require 'psych/helper'
2
+
3
+ module Psych
4
+ class TestStringTainted < TestCase
5
+ class Tainted < Handler
6
+ attr_reader :tc
7
+
8
+ def initialize tc
9
+ @tc = tc
10
+ end
11
+
12
+ def start_document version, tags, implicit
13
+ tags.flatten.each do |tag|
14
+ assert_taintedness tag
15
+ end
16
+ end
17
+
18
+ def alias name
19
+ assert_taintedness name
20
+ end
21
+
22
+ def scalar value, anchor, tag, plain, quoted, style
23
+ assert_taintedness value
24
+ assert_taintedness tag if tag
25
+ assert_taintedness anchor if anchor
26
+ end
27
+
28
+ def start_sequence anchor, tag, implicit, style
29
+ assert_taintedness tag if tag
30
+ assert_taintedness anchor if anchor
31
+ end
32
+
33
+ def start_mapping anchor, tag, implicit, style
34
+ assert_taintedness tag if tag
35
+ assert_taintedness anchor if anchor
36
+ end
37
+
38
+ def assert_taintedness thing, message = "'#{thing}' should be tainted"
39
+ tc.assert thing.tainted?, message
40
+ end
41
+ end
42
+
43
+ class Untainted < Tainted
44
+ def assert_taintedness thing, message = "'#{thing}' should not be tainted"
45
+ tc.assert !thing.tainted?, message
46
+ end
47
+ end
48
+
49
+
50
+ def setup
51
+ handler = Tainted.new self
52
+ @parser = Psych::Parser.new handler
53
+ end
54
+
55
+ def test_tags_are_tainted
56
+ assert_taintedness "%TAG !yaml! tag:yaml.org,2002:\n---\n!yaml!str \"foo\""
57
+ end
58
+
59
+ def test_alias
60
+ assert_taintedness "--- &ponies\n- foo\n- *ponies"
61
+ end
62
+
63
+ def test_scalar
64
+ assert_taintedness "--- ponies"
65
+ end
66
+
67
+ def test_anchor
68
+ assert_taintedness "--- &hi ponies"
69
+ end
70
+
71
+ def test_scalar_tag
72
+ assert_taintedness "--- !str ponies"
73
+ end
74
+
75
+ def test_seq_start_tag
76
+ assert_taintedness "--- !!seq [ a ]"
77
+ end
78
+
79
+ def test_seq_start_anchor
80
+ assert_taintedness "--- &zomg [ a ]"
81
+ end
82
+
83
+ def test_seq_mapping_tag
84
+ assert_taintedness "--- !!map { a: b }"
85
+ end
86
+
87
+ def test_seq_mapping_anchor
88
+ assert_taintedness "--- &himom { a: b }"
89
+ end
90
+
91
+ def assert_taintedness string
92
+ @parser.parse string.taint
93
+ end
94
+ end
95
+
96
+ class TestStringUntainted < TestStringTainted
97
+ def setup
98
+ handler = Untainted.new self
99
+ @parser = Psych::Parser.new handler
100
+ end
101
+
102
+ def assert_taintedness string
103
+ @parser.parse string
104
+ end
105
+ end
106
+
107
+ class TestStringIOUntainted < TestStringTainted
108
+ def setup
109
+ handler = Untainted.new self
110
+ @parser = Psych::Parser.new handler
111
+ end
112
+
113
+ def assert_taintedness string
114
+ @parser.parse StringIO.new(string)
115
+ end
116
+ end
117
+
118
+ class TestIOTainted < TestStringTainted
119
+ def assert_taintedness string
120
+ t = Tempfile.new(['something', 'yml'])
121
+ t.binmode
122
+ t.write string
123
+ t.close
124
+ File.open(t.path) { |f| @parser.parse f }
125
+ t.close(true)
126
+ end
127
+ end
128
+ end
@@ -14,6 +14,12 @@ class Psych_Unit_Tests < Psych::TestCase
14
14
  Psych.domain_types.clear
15
15
  end
16
16
 
17
+ def test_syck_compat
18
+ time = Time.utc(2010, 10, 10)
19
+ yaml = Psych.dump time
20
+ assert_match "2010-10-10 00:00:00.000000000 Z", yaml
21
+ end
22
+
17
23
  # [ruby-core:34969]
18
24
  def test_regexp_with_n
19
25
  assert_cycle(Regexp.new('',0,'n'))
metadata CHANGED
@@ -1,71 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: psych
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 0
10
- version: 1.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Aaron Patterson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-30 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-05-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rake-compiler
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153250500 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 0
32
- - 4
33
- - 1
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.4.1
35
22
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: hoe
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153250500
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &2153250040 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 41
46
- segments:
47
- - 2
48
- - 9
49
- - 1
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
50
32
  version: 2.9.1
51
33
  type: :development
52
- version_requirements: *id002
53
- description: |-
54
- Psych is a YAML parser and emitter. Psych leverages libyaml[http://libyaml.org]
55
- for it's YAML parsing and emitting capabilities. In addition to wrapping
34
+ prerelease: false
35
+ version_requirements: *2153250040
36
+ description: ! 'Psych is a YAML parser and emitter. Psych leverages libyaml[http://libyaml.org]
37
+
38
+ for it''s YAML parsing and emitting capabilities. In addition to wrapping
39
+
56
40
  libyaml, Psych also knows how to serialize and de-serialize most Ruby objects
57
- to and from the YAML format.
58
- email:
41
+
42
+ to and from the YAML format.'
43
+ email:
59
44
  - aaronp@rubyforge.org
60
45
  executables: []
61
-
62
- extensions:
46
+ extensions:
63
47
  - ext/psych/extconf.rb
64
- extra_rdoc_files:
48
+ extra_rdoc_files:
65
49
  - Manifest.txt
66
50
  - CHANGELOG.rdoc
67
51
  - README.rdoc
68
- files:
52
+ files:
69
53
  - .autotest
70
54
  - CHANGELOG.rdoc
71
55
  - Manifest.txt
@@ -146,6 +130,7 @@ files:
146
130
  - test/psych/test_string.rb
147
131
  - test/psych/test_struct.rb
148
132
  - test/psych/test_symbol.rb
133
+ - test/psych/test_tainted.rb
149
134
  - test/psych/test_to_yaml_properties.rb
150
135
  - test/psych/test_tree_builder.rb
151
136
  - test/psych/test_yaml.rb
@@ -154,44 +139,33 @@ files:
154
139
  - test/psych/visitors/test_to_ruby.rb
155
140
  - test/psych/visitors/test_yaml_tree.rb
156
141
  - .gemtest
157
- has_rdoc: true
158
142
  homepage: http://github.com/tenderlove/psych
159
143
  licenses: []
160
-
161
144
  post_install_message:
162
- rdoc_options:
145
+ rdoc_options:
163
146
  - --main
164
147
  - README.rdoc
165
- require_paths:
148
+ require_paths:
166
149
  - lib
167
- required_ruby_version: !ruby/object:Gem::Requirement
150
+ required_ruby_version: !ruby/object:Gem::Requirement
168
151
  none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- hash: 55
173
- segments:
174
- - 1
175
- - 9
176
- - 2
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
177
155
  version: 1.9.2
178
- required_rubygems_version: !ruby/object:Gem::Requirement
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
157
  none: false
180
- requirements:
181
- - - ">="
182
- - !ruby/object:Gem::Version
183
- hash: 3
184
- segments:
185
- - 0
186
- version: "0"
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
187
162
  requirements: []
188
-
189
163
  rubyforge_project: psych
190
- rubygems_version: 1.6.1
164
+ rubygems_version: 1.8.2
191
165
  signing_key:
192
166
  specification_version: 3
193
167
  summary: Psych is a YAML parser and emitter
194
- test_files:
168
+ test_files:
195
169
  - test/psych/json/test_stream.rb
196
170
  - test/psych/nodes/test_enumerable.rb
197
171
  - test/psych/test_alias_and_anchor.rb
@@ -223,6 +197,7 @@ test_files:
223
197
  - test/psych/test_string.rb
224
198
  - test/psych/test_struct.rb
225
199
  - test/psych/test_symbol.rb
200
+ - test/psych/test_tainted.rb
226
201
  - test/psych/test_to_yaml_properties.rb
227
202
  - test/psych/test_tree_builder.rb
228
203
  - test/psych/test_yaml.rb