Skip to content

Commit fd4b2e8

Browse files
author
Miguel Angel Ajo Pelayo
committed
SafeYAML fix, safeyaml loaded the examples as an array of hashes instead of a hash
also fixes bug where rack.input (aka as POST content on PUT/DELETE for rails) got cleared, making tests fail on delete or put that had parameters into it
1 parent c4a766e commit fd4b2e8

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/apipie/application.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ def recorded_examples
207207
return @recorded_examples if @recorded_examples
208208
tape_file = File.join(Rails.root,"doc","apipie_examples.yml")
209209
if File.exists?(tape_file)
210-
@recorded_examples = YAML.load_file(tape_file)
210+
#if SafeYAML gem is enabled, it will load examples as an array of Hash, instead of hash
211+
if defined? SafeYAML
212+
@recorded_examples = YAML.load_file(tape_file, :safe=>false)
213+
else
214+
@recorded_examples = YAML.load_file(tape_file)
215+
end
211216
else
212217
@recorded_examples = {}
213218
end

lib/apipie/extractor/recorder.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def analyse_env(env)
1313
@params.merge!(env["action_dispatch.request.request_parameters"] || {})
1414
if data = parse_data(env["rack.input"].read)
1515
@request_data = data
16+
env["rack.input"].rewind
1617
end
1718
end
1819

lib/apipie/extractor/writer.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def load_new_examples
9999

100100
def load_old_examples
101101
if File.exists?(@examples_file)
102-
return YAML.load(File.read(@examples_file))
102+
if defined? SafeYAML
103+
return YAML.load_file(@examples_file, :safe=>false)
104+
else
105+
return YAML.load_file(@examples_file)
106+
end
103107
end
104108
return {}
105109
end

0 commit comments

Comments
 (0)