actionpack 3.1.0.rc2 → 3.1.0.rc3

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

Potentially problematic release.


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

data/CHANGELOG CHANGED
@@ -1,5 +1,34 @@
1
1
  *Rails 3.1.0 (unreleased)*
2
2
 
3
+ * Fix escape_js to work correctly with the new SafeBuffer restriction [Paul Gallagher]
4
+
5
+ * Brought back alternative convention for namespaced models in i18n [thoefer]
6
+
7
+ Now the key can be either "namespace.model" or "namespace/model" until further deprecation.
8
+
9
+ * It is prohibited to perform a in-place SafeBuffer mutation [tenderlove]
10
+
11
+ The old behavior of SafeBuffer allowed you to mutate string in place via
12
+ method like `sub!`. These methods can add unsafe strings to a safe buffer,
13
+ and the safe buffer will continue to be marked as safe.
14
+
15
+ An example problem would be something like this:
16
+
17
+ <%= link_to('hello world', @user).sub!(/hello/, params[:xss]) %>
18
+
19
+ In the above example, an untrusted string (`params[:xss]`) is added to the
20
+ safe buffer returned by `link_to`, and the untrusted content is successfully
21
+ sent to the client without being escaped. To prevent this from happening
22
+ `sub!` and other similar methods will now raise an exception when they are called on a safe buffer.
23
+
24
+ In addition to the in-place versions, some of the versions of these methods which return a copy of the string will incorrectly mark strings as safe. For example:
25
+
26
+ <%= link_to('hello world', @user).sub(/hello/, params[:xss]) %>
27
+
28
+ The new versions will now ensure that *all* strings returned by these methods on safe buffers are marked unsafe.
29
+
30
+ You can read more about this change in http://groups.google.com/group/rubyonrails-security/browse_thread/thread/2e516e7acc96c4fb
31
+
3
32
  * Warn if we cannot verify CSRF token authenticity [José Valim]
4
33
 
5
34
  * Allow AM/PM format in datetime selectors [Aditya Sanghi]
@@ -3,7 +3,7 @@ module ActionPack
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 0
6
- PRE = "rc2"
6
+ PRE = "rc3"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
@@ -51,7 +51,13 @@ module ActionView
51
51
  # This dance is needed because Builder can't use capture
52
52
  pos = output_buffer.length
53
53
  yield
54
- fragment = output_buffer.slice!(pos..-1)
54
+ if output_buffer.is_a?(ActionView::OutputBuffer)
55
+ safe_output_buffer = output_buffer.to_str
56
+ fragment = safe_output_buffer.slice!(pos..-1)
57
+ self.output_buffer = ActionView::OutputBuffer.new(safe_output_buffer)
58
+ else
59
+ fragment = output_buffer.slice!(pos..-1)
60
+ end
55
61
  controller.write_fragment(name, fragment, options)
56
62
  end
57
63
  end
@@ -18,7 +18,7 @@ module ActionView
18
18
  # $('some_element').replaceWith('<%=j render 'some/element_template' %>');
19
19
  def escape_javascript(javascript)
20
20
  if javascript
21
- javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }
21
+ javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) {|match| JS_ESCAPE_MAP[match] }
22
22
  else
23
23
  ''
24
24
  end
@@ -255,14 +255,16 @@ module ActionView
255
255
  # simple_format("<span>I'm allowed!</span> It's true.", {}, :sanitize => false)
256
256
  # # => "<p><span>I'm allowed!</span> It's true.</p>"
257
257
  def simple_format(text, html_options={}, options={})
258
- text = ''.html_safe if text.nil?
258
+ text = text ? text.to_str : ''
259
+ text = text.dup if text.frozen?
259
260
  start_tag = tag('p', html_options, true)
260
- text = sanitize(text) unless options[:sanitize] == false
261
261
  text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
262
262
  text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
263
263
  text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
264
264
  text.insert 0, start_tag
265
- text.html_safe.safe_concat("</p>")
265
+ text.concat("</p>")
266
+ text = sanitize(text) unless options[:sanitize] == false
267
+ text
266
268
  end
267
269
 
268
270
  # Creates a Cycle object whose _to_s_ method cycles through elements of an
@@ -497,14 +497,14 @@ module ActionView
497
497
  }.compact
498
498
  extras = extras.empty? ? '' : '?' + ERB::Util.html_escape(extras.join('&'))
499
499
 
500
- email_address_obfuscated = email_address.dup
500
+ email_address_obfuscated = email_address.to_str
501
501
  email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
502
502
  email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
503
503
  case encode
504
504
  when "javascript"
505
505
  string = ''
506
506
  html = content_tag("a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe))
507
- html = escape_javascript(html)
507
+ html = escape_javascript(html.to_str)
508
508
  "document.write('#{html}');".each_byte do |c|
509
509
  string << sprintf("%%%x", c)
510
510
  end
@@ -15,42 +15,48 @@ module Sprockets
15
15
  end
16
16
  end
17
17
 
18
- def javascript_include_tag(source, options = {})
18
+ def javascript_include_tag(*sources)
19
+ options = sources.extract_options!
19
20
  debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
20
21
  body = options.key?(:body) ? options.delete(:body) : false
21
22
 
22
- if debug && asset = asset_paths.asset_for(source, 'js')
23
- asset.to_a.map { |dep|
24
- javascript_include_tag(dep, :debug => false, :body => true)
25
- }.join("\n").html_safe
26
- else
27
- options = {
28
- 'type' => "text/javascript",
29
- 'src' => asset_path(source, 'js', body)
30
- }.merge(options.stringify_keys)
23
+ sources.collect do |source|
24
+ if debug && asset = asset_paths.asset_for(source, 'js')
25
+ asset.to_a.map { |dep|
26
+ javascript_include_tag(dep, :debug => false, :body => true)
27
+ }.join("\n").html_safe
28
+ else
29
+ tag_options = {
30
+ 'type' => "text/javascript",
31
+ 'src' => asset_path(source, 'js', body)
32
+ }.merge(options.stringify_keys)
31
33
 
32
- content_tag 'script', "", options
33
- end
34
+ content_tag 'script', "", tag_options
35
+ end
36
+ end.join("\n").html_safe
34
37
  end
35
38
 
36
- def stylesheet_link_tag(source, options = {})
39
+ def stylesheet_link_tag(*sources)
40
+ options = sources.extract_options!
37
41
  debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
38
42
  body = options.key?(:body) ? options.delete(:body) : false
39
43
 
40
- if debug && asset = asset_paths.asset_for(source, 'css')
41
- asset.to_a.map { |dep|
42
- stylesheet_link_tag(dep, :debug => false, :body => true)
43
- }.join("\n").html_safe
44
- else
45
- options = {
46
- 'rel' => "stylesheet",
47
- 'type' => "text/css",
48
- 'media' => "screen",
49
- 'href' => asset_path(source, 'css', body)
50
- }.merge(options.stringify_keys)
44
+ sources.collect do |source|
45
+ if debug && asset = asset_paths.asset_for(source, 'css')
46
+ asset.to_a.map { |dep|
47
+ stylesheet_link_tag(dep, :debug => false, :body => true)
48
+ }.join("\n").html_safe
49
+ else
50
+ tag_options = {
51
+ 'rel' => "stylesheet",
52
+ 'type' => "text/css",
53
+ 'media' => "screen",
54
+ 'href' => asset_path(source, 'css', body)
55
+ }.merge(options.stringify_keys)
51
56
 
52
- tag 'link', options
53
- end
57
+ tag 'link', tag_options
58
+ end
59
+ end.join("\n").html_safe
54
60
  end
55
61
 
56
62
  private
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424097
4
+ hash: 15424099
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
10
  - rc
11
- - 2
12
- version: 3.1.0.rc2
11
+ - 3
12
+ version: 3.1.0.rc3
13
13
  platform: ruby
14
14
  authors:
15
15
  - David Heinemeier Hansson
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-06-07 00:00:00 Z
20
+ date: 2011-06-08 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: activesupport
@@ -27,14 +27,14 @@ dependencies:
27
27
  requirements:
28
28
  - - "="
29
29
  - !ruby/object:Gem::Version
30
- hash: 15424097
30
+ hash: 15424099
31
31
  segments:
32
32
  - 3
33
33
  - 1
34
34
  - 0
35
35
  - rc
36
- - 2
37
- version: 3.1.0.rc2
36
+ - 3
37
+ version: 3.1.0.rc3
38
38
  type: :runtime
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "="
47
47
  - !ruby/object:Gem::Version
48
- hash: 15424097
48
+ hash: 15424099
49
49
  segments:
50
50
  - 3
51
51
  - 1
52
52
  - 0
53
53
  - rc
54
- - 2
55
- version: 3.1.0.rc2
54
+ - 3
55
+ version: 3.1.0.rc3
56
56
  type: :runtime
57
57
  version_requirements: *id002
58
58
  - !ruby/object:Gem::Dependency