Skip to content

Commit b8da8a0

Browse files
Andrew Dupontsavetheclocktower
Andrew Dupont
authored andcommitted
Fix YAML parsing issue that emerged in Ruby 1.9.
In 1.8.7: irb(main):001:0> require 'yaml' => true irb(main):007:0> YAML.load('foo: [?]') => {"foo"=>["?"]} In 1.9.3: irb(main):002:0> YAML.load('foo: [?]') Psych::SyntaxError: (<unknown>): did not find expected ',' or ']' while parsing a flow sequence at line 1 column 6 from /Users/andrew.dupont/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/psych.rb:203:in `parse' from /Users/andrew.dupont/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/psych.rb:203:in `parse_stream' from /Users/andrew.dupont/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/psych.rb:151:in `parse' from /Users/andrew.dupont/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/psych.rb:127:in `load' from (irb):2 from /Users/andrew.dupont/.rbenv/versions/1.9.3-p392/bin/irb:12:in `<main>' In PDoc, `?` can be an argument type and a return type. When it's an argument type, we end up with `types: [?]` in the YAML file, and though that was OK before Psych existed, it's not OK now. This was preventing documentation from being generated from at least Ruby 1.9.3 onward. The solution is to put quotes around the types so that YAML knows we mean for them to be strings. This ends up not being a problem for the return type (`return_value` in the YAML) because it ends up being escaped, as are most of the values in the YAML output.
1 parent c01ea40 commit b8da8a0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/pdoc/parser/documentation_nodes.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def section_name
183183
def to_yaml
184184
str = "id: #{full_name.inspect}"
185185
str << "\nparent_id: #{parent_id.inspect}" if parent_id
186-
str << "\ntype: #{type}"
186+
str << "\ntype: #{type.inspect}"
187187
str << "\nsuperclass_id: #{superclass.inspect}" if respond_to?(:superclass) && superclass
188188
str << "\nincluded: #{mixins.inspect}" if respond_to?(:mixins) && !mixins.empty?
189189
str << "\nline_number: #{src_code_line}"
@@ -334,9 +334,10 @@ def serialize_signatures(str)
334334
def serialize_arguments(str)
335335
str << "\narguments:"
336336
arguments.each do |arg|
337+
types = arg.types.map { |type| type.inspect }
337338
str << "\n -"
338-
str << "\n name: #{arg.name}"
339-
str << "\n types: [#{arg.types.join(', ')}]" unless arg.types.empty?
339+
str << "\n name: #{arg.name.inspect}"
340+
str << "\n types: [#{types.join(', ')}]" unless types.empty?
340341
str << "\n description: >"
341342
str << "\n #{arg.description}\n"
342343
end

0 commit comments

Comments
 (0)