aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-04-04 19:37:29 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-04-04 19:37:29 +0000
commite714b25723b674bb6d66af40ea9047166907616b (patch)
tree757a0368a8cef19d5c951d68162ea73dabb6edaa
parent62dc792a484e6e62fb2fb87fd47819144c5e3301 (diff)
downloadrails-e714b25723b674bb6d66af40ea9047166907616b.tar.gz
rails-e714b25723b674bb6d66af40ea9047166907616b.tar.bz2
rails-e714b25723b674bb6d66af40ea9047166907616b.zip
Update the diagnostics template skip the useless '<controller not set>' text.
Fix symbol extensions test case. Clean paths inside of exception messages and traces. Add Pathname.clean_within for cleaning all the paths inside of a string. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4158 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml6
-rw-r--r--activesupport/CHANGELOG4
-rw-r--r--activesupport/lib/active_support/core_ext/exception.rb19
-rw-r--r--activesupport/lib/active_support/core_ext/pathname.rb7
-rw-r--r--activesupport/lib/active_support/core_ext/pathname/clean_within.rb14
-rw-r--r--activesupport/test/core_ext/exception_test.rb23
-rw-r--r--activesupport/test/core_ext/symbol_test.rb8
-rw-r--r--activesupport/test/core_ext/symbol_tests.rb (renamed from activesupport/test/core_ext/symbol.rb)0
9 files changed, 72 insertions, 11 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 9fb5b29cc0..d34ae7fc02 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Update the diagnostics template skip the useless '<controller not set>' text. [Nicholas Seckar]
+
* CHANGED DEFAULT: Don't parse YAML input by default, but keep it available as an easy option [DHH]
* Add additional autocompleter options [aballai, Thomas Fuchs]
diff --git a/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml b/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml
index 584659252a..fa48b62f6f 100644
--- a/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml
+++ b/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml
@@ -1,6 +1,8 @@
<h1>
- <%=h @exception.class.to_s %> in
- <%=h (@request.parameters["controller"] || "<controller not set>").capitalize %>#<%=h @request.parameters["action"] || "<action not set>" %>
+ <%=h @exception.class.to_s %>
+ <% if @request.parameters['controller'] %>
+ in <%=h @request.parameters['controller'].humanize %>Controller<% if @request.parameters['action'] %>#<%=h @request.parameters['action'] %><% end %>
+ <% end %>
</h1>
<pre><%=h @exception.clean_message %></pre>
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 4886912b31..18017ea783 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,9 @@
* SVN *
+* Clean paths inside of exception messages and traces. [Nicholas Seckar]
+
+* Add Pathname.clean_within for cleaning all the paths inside of a string. [Nicholas Seckar]
+
* provide an empty Dependencies::LoadingModule.load which prints deprecation warnings. Lets 1.0 applications function with .13-style environment.rb.
*1.3.0* (March 27th, 2005)
diff --git a/activesupport/lib/active_support/core_ext/exception.rb b/activesupport/lib/active_support/core_ext/exception.rb
index 0b65af7bf8..2e3965117b 100644
--- a/activesupport/lib/active_support/core_ext/exception.rb
+++ b/activesupport/lib/active_support/core_ext/exception.rb
@@ -1,25 +1,30 @@
-class Exception
- alias :clean_message :message
+class Exception # :nodoc:
+ def clean_message
+ Pathname.clean_within message
+ end
TraceSubstitutions = []
- FrameworkRegexp = /generated_code|vendor|dispatch|ruby|script\/\w+/
+ FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/
def clean_backtrace
backtrace.collect do |line|
- TraceSubstitutions.inject(line) do |line, (regexp, sub)|
+ Pathname.clean_within(TraceSubstitutions.inject(line) do |line, (regexp, sub)|
line.gsub regexp, sub
- end
+ end)
end
end
def application_backtrace
before_application_frame = true
- clean_backtrace.reject do |line|
- non_app_frame = !! (line =~ FrameworkRegexp)
+ trace = clean_backtrace.reject do |line|
+ non_app_frame = (line =~ FrameworkRegexp)
before_application_frame = false unless non_app_frame
non_app_frame && ! before_application_frame
end
+
+ # If we didn't find any application frames, return an empty app trace.
+ before_application_frame ? [] : trace
end
def framework_backtrace
diff --git a/activesupport/lib/active_support/core_ext/pathname.rb b/activesupport/lib/active_support/core_ext/pathname.rb
new file mode 100644
index 0000000000..9e78c273d9
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/pathname.rb
@@ -0,0 +1,7 @@
+require 'pathname'
+require File.dirname(__FILE__) + '/pathname/clean_within'
+
+class Pathname#:nodoc:
+ extend ActiveSupport::CoreExtensions::Pathname::CleanWithin
+end
+
diff --git a/activesupport/lib/active_support/core_ext/pathname/clean_within.rb b/activesupport/lib/active_support/core_ext/pathname/clean_within.rb
new file mode 100644
index 0000000000..ae03e1bc5a
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/pathname/clean_within.rb
@@ -0,0 +1,14 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Pathname #:nodoc:
+ module CleanWithin
+ # Clean the paths contained in the provided string.
+ def clean_within(string)
+ string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
+ new(path).cleanpath
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/activesupport/test/core_ext/exception_test.rb b/activesupport/test/core_ext/exception_test.rb
index 58f1ba5540..9b7afb1913 100644
--- a/activesupport/test/core_ext/exception_test.rb
+++ b/activesupport/test/core_ext/exception_test.rb
@@ -41,6 +41,25 @@ class ExceptionExtTests < Test::Unit::TestCase
assert_kind_of Exception, e
assert_equal ['vendor/file.rb some stuff', ' vendor/file.rb some stuff'], e.framework_backtrace
end
-
-end \ No newline at end of file
+ def test_backtrace_should_clean_paths
+ Exception::TraceSubstitutions << [/\s*hidden.*/, '']
+ e = get_exception RuntimeError, 'RAWR', ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all']
+ assert_kind_of Exception, e
+ assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace
+ end
+
+ def test_clean_message_should_clean_paths
+ Exception::TraceSubstitutions << [/\s*hidden.*/, '']
+ e = get_exception RuntimeError, "I dislike a/z/x/../../b/y/../c", ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all']
+ assert_kind_of Exception, e
+ assert_equal "I dislike a/b/c", e.clean_message
+ end
+
+ def test_app_trace_should_be_empty_when_no_app_frames
+ Exception::TraceSubstitutions << [/\s*hidden.*/, '']
+ e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'generated/bhal.rb', ' vendor/file.rb some stuff', 'generated/almost all']
+ assert_kind_of Exception, e
+ assert_equal [], e.application_backtrace
+ end
+end
diff --git a/activesupport/test/core_ext/symbol_test.rb b/activesupport/test/core_ext/symbol_test.rb
new file mode 100644
index 0000000000..fec504d9d1
--- /dev/null
+++ b/activesupport/test/core_ext/symbol_test.rb
@@ -0,0 +1,8 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol'
+
+class SymbolTests < Test::Unit::TestCase
+ def test_to_proc
+ assert_equal %w(one two three), [:one, :two, :three].map(&:to_s)
+ end
+end
diff --git a/activesupport/test/core_ext/symbol.rb b/activesupport/test/core_ext/symbol_tests.rb
index ae2c585fc2..ae2c585fc2 100644
--- a/activesupport/test/core_ext/symbol.rb
+++ b/activesupport/test/core_ext/symbol_tests.rb