rdoc 4.0.0.preview2.1 → 4.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (64) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CVE-2013-0256.rdoc +49 -0
  5. data/History.rdoc +33 -1
  6. data/Manifest.txt +3 -1
  7. data/Rakefile +2 -1
  8. data/lib/rdoc.rb +1 -1
  9. data/lib/rdoc/any_method.rb +2 -0
  10. data/lib/rdoc/attr.rb +2 -0
  11. data/lib/rdoc/class_module.rb +1 -0
  12. data/lib/rdoc/code_object.rb +7 -0
  13. data/lib/rdoc/cross_reference.rb +1 -1
  14. data/lib/rdoc/encoding.rb +3 -1
  15. data/lib/rdoc/generator/darkfish.rb +1 -1
  16. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +9 -7
  17. data/lib/rdoc/generator/template/darkfish/rdoc.css +21 -0
  18. data/lib/rdoc/generator/template/json_index/.document +1 -0
  19. data/lib/rdoc/markup/attribute_manager.rb +5 -7
  20. data/lib/rdoc/markup/formatter.rb +75 -0
  21. data/lib/rdoc/markup/to_html.rb +9 -57
  22. data/lib/rdoc/markup/to_markdown.rb +55 -0
  23. data/lib/rdoc/parser.rb +35 -11
  24. data/lib/rdoc/parser/changelog.rb +9 -1
  25. data/lib/rdoc/parser/ruby.rb +23 -4
  26. data/lib/rdoc/rd/block_parser.rb +3 -2
  27. data/lib/rdoc/rd/block_parser.ry +3 -2
  28. data/lib/rdoc/rd/inline_parser.rb +1 -1
  29. data/lib/rdoc/rd/inline_parser.ry +1 -1
  30. data/lib/rdoc/ruby_lex.rb +20 -4
  31. data/lib/rdoc/ruby_token.rb +1 -0
  32. data/lib/rdoc/servlet.rb +25 -16
  33. data/lib/rdoc/store.rb +9 -4
  34. data/lib/rdoc/tom_doc.rb +1 -1
  35. data/lib/rdoc/top_level.rb +2 -1
  36. data/test/{test.ja.large.rdoc → test.ja.largedoc} +0 -0
  37. data/test/test_rdoc_any_method.rb +16 -7
  38. data/test/test_rdoc_attr.rb +4 -0
  39. data/test/test_rdoc_class_module.rb +2 -0
  40. data/test/test_rdoc_comment.rb +1 -1
  41. data/test/test_rdoc_constant.rb +4 -0
  42. data/test/test_rdoc_cross_reference.rb +15 -0
  43. data/test/test_rdoc_encoding.rb +1 -1
  44. data/test/test_rdoc_generator_markup.rb +4 -1
  45. data/test/test_rdoc_markup_formatter.rb +91 -0
  46. data/test/test_rdoc_markup_to_html.rb +52 -23
  47. data/test/test_rdoc_markup_to_markdown.rb +31 -0
  48. data/test/test_rdoc_options.rb +11 -0
  49. data/test/test_rdoc_parser.rb +50 -5
  50. data/test/test_rdoc_parser_c.rb +34 -11
  51. data/test/test_rdoc_parser_changelog.rb +32 -4
  52. data/test/test_rdoc_parser_markdown.rb +11 -5
  53. data/test/test_rdoc_parser_rd.rb +15 -5
  54. data/test/test_rdoc_parser_ruby.rb +23 -0
  55. data/test/test_rdoc_rd_block_parser.rb +141 -123
  56. data/test/test_rdoc_rd_inline_parser.rb +6 -1
  57. data/test/test_rdoc_rdoc.rb +5 -2
  58. data/test/test_rdoc_ruby_lex.rb +51 -5
  59. data/test/test_rdoc_servlet.rb +43 -5
  60. data/test/test_rdoc_store.rb +55 -4
  61. data/test/test_rdoc_tom_doc.rb +37 -0
  62. data/test/test_rdoc_top_level.rb +17 -1
  63. metadata +29 -34
  64. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: be465a9f7229b4fa46271d90e7102066498c0b4d
4
- data.tar.gz: f5297b952027d39046fcea6d3c4ead0fe569f40c
5
- !binary "U0hBNTEy":
6
- metadata.gz: a4bbe645b202903651d0b3fa0d79bd331c2b7becd9d7feed0d24d215821a6625c27f6db475d3c495ddc3652651afe00c75d7c3a7dadad7c97948c7934c7d675a
7
- data.tar.gz: 297ea3814b07df111090a99500b10f9f9a4e99448e9626b1f304d659e4b5d1fdf03a8f60562ecb25448e74e661efeae87d982f67a84f857c06db8ca9319cc527
2
+ SHA1:
3
+ metadata.gz: d63ee2bd18438ed61f20690a074f2851e1c78453
4
+ data.tar.gz: 75312953f9b1c4430bebd2a3d9a1911e1e505a1e
5
+ SHA512:
6
+ metadata.gz: 7d2643d503c3908a72bbb242066390f27c5f123e5c3db1ebc0989d90ff160ce599cd3d18db8fa4ca05f2f51e0f76a51ea8321ec024f5709adbba2faaddc8c90a
7
+ data.tar.gz: da8ae787c4c627055b7dccc2167fd58e031f69ce95ee74e4d51524bb977c72efb357b3d1f1c74b4a35935fadde46e57fe6a30b23af699f3e5b9dfffb78913fce
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,49 @@
1
+ = RDoc 2.3.0 through 3.12 XSS Exploit
2
+
3
+ RDoc documentation generated by rdoc 2.3.0 through rdoc 3.12 and prereleases up
4
+ to rdoc 4.0.0.preview2.1 are vulnerable to an XSS exploit. This exploit may
5
+ lead to cookie disclosure to third parties.
6
+
7
+ The exploit exists in darkfish.js which is copied from the RDoc install
8
+ location to the generated documentation.
9
+
10
+ RDoc is a static documentation generation tool. Patching the library itself
11
+ is insufficient to correct this exploit. Those hosting rdoc documentation will
12
+ need to apply the following patch. If applied while ignoring whitespace, this
13
+ patch will correct all affected versions:
14
+
15
+ diff --git darkfish.js darkfish.js
16
+ index 4be722f..f26fd45 100644
17
+ --- darkfish.js
18
+ +++ darkfish.js
19
+ @@ -109,13 +109,15 @@ function hookSearch() {
20
+ function highlightTarget( anchor ) {
21
+ console.debug( "Highlighting target '%s'.", anchor );
22
+
23
+ - $("a[name=" + anchor + "]").each( function() {
24
+ - if ( !$(this).parent().parent().hasClass('target-section') ) {
25
+ - console.debug( "Wrapping the target-section" );
26
+ - $('div.method-detail').unwrap( 'div.target-section' );
27
+ - $(this).parent().wrap( '<div class="target-section"></div>' );
28
+ - } else {
29
+ - console.debug( "Already wrapped." );
30
+ + $("a[name]").each( function() {
31
+ + if ( $(this).attr("name") == anchor ) {
32
+ + if ( !$(this).parent().parent().hasClass('target-section') ) {
33
+ + console.debug( "Wrapping the target-section" );
34
+ + $('div.method-detail').unwrap( 'div.target-section' );
35
+ + $(this).parent().wrap( '<div class="target-section"></div>' );
36
+ + } else {
37
+ + console.debug( "Already wrapped." );
38
+ + }
39
+ }
40
+ });
41
+ };
42
+
43
+ RDoc 3.9.5, 3.12.1 and RDoc 4.0.0.rc.2 and newer are not vulnerable to this
44
+ exploit.
45
+
46
+ This exploit was discovered by Evgeny Ermakov <corwmh@gmail.com>.
47
+
48
+ This vulnerability has been assigned the CVE identifier CVE-2013-0256.
49
+
data/History.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- === 4.0.0.preview2.1 / 2012-12-14
1
+ === 4.0.0.rc.2 / 2013-02-05
2
2
 
3
3
  As a preview release, please file bugs for any problems you have with rdoc at
4
4
  https://github.com/rdoc/rdoc/issues
@@ -10,6 +10,38 @@ Notable feature additions are markdown support and an WEBrick servlet that can
10
10
  serve HTML from an ri store. (This means that RubyGems 2.0+ no longer needs
11
11
  to build HTML documentation when installing gems.)
12
12
 
13
+ * Minor enhancements
14
+ * Added current heading and page-top links to HTML headings.
15
+
16
+ * Bug fixes
17
+ * Fixed an XSS exploit in darkfish.js. This could lead to cookie disclosure
18
+ to third parties. See CVE-2013-0256[rdoc-ref:CVE-2013-0256.rdoc] for full
19
+ details including a patch you can apply to generated RDoc documentation.
20
+ * Fixed parsing of multibyte files with incomplete characters at byte 1024.
21
+ Ruby bug #6393 by nobu, patch by Nobuyoshi Nakada and Yui NARUSE.
22
+ * Fixed rdoc -E. Ruby Bug #6392 and (modified) patch by Nobuyoshi Nakada
23
+ * Added link handling to Markdown output. Bug #160 by burningTyger.
24
+ * Fixed HEREDOC output for the limited case of a heredoc followed by a line
25
+ end. When a HEREDOC is not followed by a line end RDoc is not currently
26
+ smart enough to restore the source correctly. Bug #162 by Zachary Scott.
27
+ * Fixed parsing of executables with shebang and encoding comments. Bug #161
28
+ by Marcus Stollsteimer
29
+ * RDoc now ignores methods defined on constants instead of creating a fake
30
+ module. Bug #163 by Zachary Scott.
31
+ * Fixed ChangeLog parsing for FFI gem. Bug #165 by Zachary Scott.
32
+ * RDoc now links \#=== methods. Bug #164 by Zachary Scott.
33
+ * Allow [] following argument names for TomDoc. Bug #167 by Ellis Berner.
34
+ * Fixed the RDoc servlet for home and site directories. Bug #170 by Thomas
35
+ Leitner.
36
+ * Fixed references to methods in the RDoc servlet. Bug #171 by Thomas
37
+ Leitner.
38
+ * Fixed debug message when generating the darkfish root page. Pull Request
39
+ #174 by Thomas Leitner.
40
+ * Fixed deletion of attribute ri data when a class was loaded then saved.
41
+ Issue #171 by Thomas Leitner.
42
+
43
+ === 4.0.0.preview2.1 / 2012-12-14
44
+
13
45
  * Minor enhancements
14
46
  * Added --page-dir option to give pretty names for a FAQ, guides, or other
15
47
  documentation you write that is not stored in the project root. For
data/Manifest.txt CHANGED
@@ -1,5 +1,6 @@
1
1
  .autotest
2
2
  .document
3
+ CVE-2013-0256.rdoc
3
4
  DEVELOPERS.rdoc
4
5
  History.rdoc
5
6
  LEGAL.rdoc
@@ -85,6 +86,7 @@ lib/rdoc/generator/template/darkfish/rdoc.css
85
86
  lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml
86
87
  lib/rdoc/generator/template/darkfish/servlet_root.rhtml
87
88
  lib/rdoc/generator/template/darkfish/table_of_contents.rhtml
89
+ lib/rdoc/generator/template/json_index/.document
88
90
  lib/rdoc/generator/template/json_index/js/navigation.js
89
91
  lib/rdoc/generator/template/json_index/js/searcher.js
90
92
  lib/rdoc/ghost_method.rb
@@ -202,7 +204,7 @@ test/MarkdownTest_1.0.3/Tidyness.text
202
204
  test/README
203
205
  test/binary.dat
204
206
  test/hidden.zip.txt
205
- test/test.ja.large.rdoc
207
+ test/test.ja.largedoc
206
208
  test/test.ja.rdoc
207
209
  test/test.ja.txt
208
210
  test/test.txt
data/Rakefile CHANGED
@@ -48,6 +48,7 @@ Depending on your version of ruby, you may need to install ruby rdoc/ri data:
48
48
  self.testlib = :minitest
49
49
  self.extra_rdoc_files += %w[
50
50
  DEVELOPERS.rdoc
51
+ CVE-2013-0256.rdoc
51
52
  History.rdoc
52
53
  LICENSE.rdoc
53
54
  LEGAL.rdoc
@@ -62,7 +63,7 @@ Depending on your version of ruby, you may need to install ruby rdoc/ri data:
62
63
  require_ruby_version '>= 1.8.7'
63
64
  extra_deps << ['json', '~> 1.4']
64
65
  extra_dev_deps << ['racc', '~> 1.4']
65
- extra_dev_deps << ['minitest', '~> 2']
66
+ extra_dev_deps << ['minitest', '~> 4']
66
67
  extra_dev_deps << ['ZenTest', '~> 4']
67
68
 
68
69
  extra_rdoc_files << 'Rakefile'
data/lib/rdoc.rb CHANGED
@@ -64,7 +64,7 @@ module RDoc
64
64
  ##
65
65
  # RDoc version you are using
66
66
 
67
- VERSION = '4.0.0.preview2.1'
67
+ VERSION = '4.0.0.rc.2'
68
68
 
69
69
  ##
70
70
  # Method visibilities
@@ -123,6 +123,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
123
123
  # * #parent_name
124
124
 
125
125
  def marshal_load array
126
+ initialize_visibility
127
+
126
128
  @dont_rename_initialize = nil
127
129
  @is_alias_for = nil
128
130
  @token_stream = nil
data/lib/rdoc/attr.rb CHANGED
@@ -121,6 +121,8 @@ class RDoc::Attr < RDoc::MethodAttr
121
121
  # * #parent_name
122
122
 
123
123
  def marshal_load array
124
+ initialize_visibility
125
+
124
126
  @aliases = []
125
127
  @parent = nil
126
128
  @parent_name = nil
@@ -323,6 +323,7 @@ class RDoc::ClassModule < RDoc::Context
323
323
  end
324
324
 
325
325
  def marshal_load array # :nodoc:
326
+ initialize_visibility
326
327
  initialize_methods_etc
327
328
  @current_section = nil
328
329
  @document_self = true
@@ -116,6 +116,13 @@ class RDoc::CodeObject
116
116
  @full_name = nil
117
117
  @store = nil
118
118
 
119
+ initialize_visibility
120
+ end
121
+
122
+ ##
123
+ # Initializes state for visibility of this CodeObject and its children.
124
+
125
+ def initialize_visibility # :nodoc:
119
126
  @document_children = true
120
127
  @document_self = true
121
128
  @done_documenting = false
@@ -18,7 +18,7 @@ class RDoc::CrossReference
18
18
  #
19
19
  # See CLASS_REGEXP_STR
20
20
 
21
- METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%)(?:\([\w.+*/=<>-]*\))?'
21
+ METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===)(?:\([\w.+*/=<>-]*\))?'
22
22
 
23
23
  ##
24
24
  # Regular expressions matching text that should potentially have
data/lib/rdoc/encoding.rb CHANGED
@@ -75,7 +75,9 @@ module RDoc::Encoding
75
75
  # Sets the encoding of +string+ based on the magic comment
76
76
 
77
77
  def self.set_encoding string
78
- first_line = string[/\A(?:#!.*\n)?.*\n/]
78
+ string =~ /\A(?:#!.*\n)?(.*\n)/
79
+
80
+ first_line = $1
79
81
 
80
82
  name = case first_line
81
83
  when /^<\?xml[^?]*encoding=(["'])(.*?)\1/ then $2
@@ -453,7 +453,7 @@ class RDoc::Generator::Darkfish
453
453
  template_file = @template_dir + 'servlet_not_found.rhtml'
454
454
  return unless template_file.exist?
455
455
 
456
- debug_msg "Rendering the servlet root page..."
456
+ debug_msg "Rendering the servlet 404 Not Found page..."
457
457
 
458
458
  rel_prefix = rel_prefix = ''
459
459
  search_index_rel_prefix = rel_prefix
@@ -109,13 +109,15 @@ function hookSearch() {
109
109
  function highlightTarget( anchor ) {
110
110
  console.debug( "Highlighting target '%s'.", anchor );
111
111
 
112
- $("a[name=" + anchor + "]").each( function() {
113
- if ( !$(this).parent().parent().hasClass('target-section') ) {
114
- console.debug( "Wrapping the target-section" );
115
- $('div.method-detail').unwrap( 'div.target-section' );
116
- $(this).parent().wrap( '<div class="target-section"></div>' );
117
- } else {
118
- console.debug( "Already wrapped." );
112
+ $("a[name]").each( function() {
113
+ if ( $(this).attr("name") == anchor ) {
114
+ if ( !$(this).parent().parent().hasClass('target-section') ) {
115
+ console.debug( "Wrapping the target-section" );
116
+ $('div.method-detail').unwrap( 'div.target-section' );
117
+ $(this).parent().wrap( '<div class="target-section"></div>' );
118
+ } else {
119
+ console.debug( "Already wrapped." );
120
+ }
119
121
  }
120
122
  });
121
123
  };
@@ -28,6 +28,27 @@ h1 {
28
28
  }
29
29
  h2,h3,h4 { margin-top: 1.5em; }
30
30
 
31
+ h1 span,
32
+ h2 span,
33
+ h3 span,
34
+ h4 span,
35
+ h5 span,
36
+ h6 span {
37
+ display: none;
38
+ padding-left: 1em;
39
+ font-size: 50%;
40
+ vertical-align: super;
41
+ }
42
+
43
+ h1:hover span,
44
+ h2:hover span,
45
+ h3:hover span,
46
+ h4:hover span,
47
+ h5:hover span,
48
+ h6:hover span {
49
+ display: inline;
50
+ }
51
+
31
52
  :link,
32
53
  :visited {
33
54
  color: #6C8C22;
@@ -0,0 +1 @@
1
+ # ignore all files in this directory
@@ -168,15 +168,13 @@ class RDoc::Markup::AttributeManager
168
168
  # Converts special sequences to RDoc attributes
169
169
 
170
170
  def convert_specials str, attrs
171
- unless @special.empty?
172
- @special.each do |regexp, attribute|
173
- str.scan(regexp) do
174
- capture = $~.size == 1 ? 0 : 1
171
+ @special.each do |regexp, attribute|
172
+ str.scan(regexp) do
173
+ capture = $~.size == 1 ? 0 : 1
175
174
 
176
- s, e = $~.offset capture
175
+ s, e = $~.offset capture
177
176
 
178
- attrs.set_attrs s, e - s, attribute | @attributes.special
179
- end
177
+ attrs.set_attrs s, e - s, attribute | @attributes.special
180
178
  end
181
179
  end
182
180
  end
@@ -17,6 +17,30 @@ class RDoc::Markup::Formatter
17
17
 
18
18
  InlineTag = Struct.new(:bit, :on, :off)
19
19
 
20
+ ##
21
+ # Converts a target url to one that is relative to a given path
22
+
23
+ def self.gen_relative_url path, target
24
+ from = File.dirname path
25
+ to, to_file = File.split target
26
+
27
+ from = from.split "/"
28
+ to = to.split "/"
29
+
30
+ from.delete '.'
31
+ to.delete '.'
32
+
33
+ while from.size > 0 and to.size > 0 and from[0] == to[0] do
34
+ from.shift
35
+ to.shift
36
+ end
37
+
38
+ from.fill ".."
39
+ from.concat to
40
+ from << to_file
41
+ File.join(*from)
42
+ end
43
+
20
44
  ##
21
45
  # Creates a new Formatter
22
46
 
@@ -35,6 +59,7 @@ class RDoc::Markup::Formatter
35
59
  @tt_bit = @attributes.bitmap_for :TT
36
60
 
37
61
  @hard_break = ''
62
+ @from_path = '.'
38
63
  end
39
64
 
40
65
  ##
@@ -51,6 +76,26 @@ class RDoc::Markup::Formatter
51
76
  end
52
77
  end
53
78
 
79
+ ##
80
+ # Adds a special for links of the form rdoc-...:
81
+
82
+ def add_special_RDOCLINK
83
+ @markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
84
+ end
85
+
86
+ ##
87
+ # Adds a special for links of the form {<text>}[<url>] and <word>[<url>]
88
+
89
+ def add_special_TIDYLINK
90
+ @markup.add_special(/(?:
91
+ \{.*?\} | # multi-word label
92
+ \b[^\s{}]+? # single-word label
93
+ )
94
+
95
+ \[\S+?\] # link target
96
+ /x, :TIDYLINK)
97
+ end
98
+
54
99
  ##
55
100
  # Add a new set of tags for an attribute. We allow separate start and end
56
101
  # tags for flexibility
@@ -178,6 +223,36 @@ class RDoc::Markup::Formatter
178
223
  end
179
224
  end
180
225
 
226
+ ##
227
+ # Extracts and a scheme, url and an anchor id from +url+ and returns them.
228
+
229
+ def parse_url url
230
+ case url
231
+ when /^rdoc-label:([^:]*)(?::(.*))?/ then
232
+ scheme = 'link'
233
+ path = "##{$1}"
234
+ id = " id=\"#{$2}\"" if $2
235
+ when /([A-Za-z]+):(.*)/ then
236
+ scheme = $1.downcase
237
+ path = $2
238
+ when /^#/ then
239
+ else
240
+ scheme = 'http'
241
+ path = url
242
+ url = "http://#{url}"
243
+ end
244
+
245
+ if scheme == 'link' then
246
+ url = if path[0, 1] == '#' then # is this meaningful?
247
+ path
248
+ else
249
+ self.class.gen_relative_url @from_path, path
250
+ end
251
+ end
252
+
253
+ [scheme, url, id]
254
+ end
255
+
181
256
  ##
182
257
  # Is +tag+ a tt tag?
183
258
 
@@ -36,30 +36,6 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
36
36
 
37
37
  attr_accessor :from_path
38
38
 
39
- ##
40
- # Converts a target url to one that is relative to a given path
41
-
42
- def self.gen_relative_url(path, target)
43
- from = File.dirname path
44
- to, to_file = File.split target
45
-
46
- from = from.split "/"
47
- to = to.split "/"
48
-
49
- from.delete '.'
50
- to.delete '.'
51
-
52
- while from.size > 0 and to.size > 0 and from[0] == to[0] do
53
- from.shift
54
- to.shift
55
- end
56
-
57
- from.fill ".."
58
- from.concat to
59
- from << to_file
60
- File.join(*from)
61
- end
62
-
63
39
  # :section:
64
40
 
65
41
  ##
@@ -79,17 +55,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
79
55
  @markup.add_special(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
80
56
  :HYPERLINK)
81
57
 
82
- # internal links
83
- @markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
84
-
85
- # and links of the form <text>[<url>]
86
- @markup.add_special(/(?:
87
- \{.*?\} | # multi-word label
88
- \b[^\s{}]+? # single-word label
89
- )
90
-
91
- \[\S+?\] # link target
92
- /x, :TIDYLINK)
58
+ add_special_RDOCLINK
59
+ add_special_TIDYLINK
93
60
 
94
61
  init_tags
95
62
  end
@@ -301,6 +268,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
301
268
 
302
269
  @res << "\n<h#{level} id=\"#{label}\">"
303
270
  @res << to_html(heading.text)
271
+ unless @options.pipe then
272
+ @res << "<span><a href=\"##{label}\">&para;</a>"
273
+ @res << " <a href=\"#documentation\">&uarr;</a></span>"
274
+ end
304
275
  @res << "</h#{level}>\n"
305
276
  end
306
277
 
@@ -325,32 +296,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
325
296
  # for img: and link: described under handle_special_HYPERLINK
326
297
 
327
298
  def gen_url url, text
328
- if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
329
- type = "link"
330
- path = "##{$1}"
331
- id = " id=\"#{$2}\"" if $2
332
- elsif url =~ /([A-Za-z]+):(.*)/ then
333
- type = $1
334
- path = $2
335
- else
336
- type = "http"
337
- path = url
338
- url = "http://#{url}"
339
- end
340
-
341
- if type == "link" then
342
- url = if path[0, 1] == '#' then # is this meaningful?
343
- path
344
- else
345
- self.class.gen_relative_url @from_path, path
346
- end
347
- end
299
+ scheme, url, id = parse_url url
348
300
 
349
- if (type == "http" or type == "https" or type == "link") and
301
+ if %w[http https link].include?(scheme) and
350
302
  url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
351
303
  "<img src=\"#{url}\" />"
352
304
  else
353
- "<a#{id} href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
305
+ "<a#{id} href=\"#{url}\">#{text.sub(%r{^#{scheme}:/*}i, '')}</a>"
354
306
  end
355
307
  end
356
308