From e714b25723b674bb6d66af40ea9047166907616b Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Tue, 4 Apr 2006 19:37:29 +0000 Subject: Update the diagnostics template skip the useless '' 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 --- actionpack/CHANGELOG | 2 ++ .../templates/rescues/diagnostics.rhtml | 6 ++++-- activesupport/CHANGELOG | 4 ++++ .../lib/active_support/core_ext/exception.rb | 19 +++++++++++------- .../lib/active_support/core_ext/pathname.rb | 7 +++++++ .../core_ext/pathname/clean_within.rb | 14 +++++++++++++ activesupport/test/core_ext/exception_test.rb | 23 ++++++++++++++++++++-- activesupport/test/core_ext/symbol.rb | 8 -------- activesupport/test/core_ext/symbol_test.rb | 8 ++++++++ activesupport/test/core_ext/symbol_tests.rb | 8 ++++++++ 10 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/pathname.rb create mode 100644 activesupport/lib/active_support/core_ext/pathname/clean_within.rb delete mode 100644 activesupport/test/core_ext/symbol.rb create mode 100644 activesupport/test/core_ext/symbol_test.rb create mode 100644 activesupport/test/core_ext/symbol_tests.rb 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 '' 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 @@

- <%=h @exception.class.to_s %> in - <%=h (@request.parameters["controller"] || "").capitalize %>#<%=h @request.parameters["action"] || "" %> + <%=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 %>

<%=h @exception.clean_message %>
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.rb b/activesupport/test/core_ext/symbol.rb deleted file mode 100644 index ae2c585fc2..0000000000 --- a/activesupport/test/core_ext/symbol.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol' - -class TestSymbol < Test::Case::TestUnit - 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_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_tests.rb b/activesupport/test/core_ext/symbol_tests.rb new file mode 100644 index 0000000000..ae2c585fc2 --- /dev/null +++ b/activesupport/test/core_ext/symbol_tests.rb @@ -0,0 +1,8 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol' + +class TestSymbol < Test::Case::TestUnit + def test_to_proc + assert_equal %w(one two three), [:one, :two, :three].map &:to_s + end +end -- cgit v1.2.3