[jruby-rack~main:d23f7789] Add spec for trailing slash chomp

  • From: nicksieger@kenai.com
  • To: commits@jruby-rack.kenai.com
  • Subject: [jruby-rack~main:d23f7789] Add spec for trailing slash chomp
  • Date: Wed, 31 Mar 2010 20:48:36 +0000

Project:    jruby-rack
Repository: main
Revision:   d23f7789b51a03f6150d5aa9ee817d8eeb9a1a71
Author:     nicksieger
Date:       2010-03-31 20:47:16 UTC
Link:       

Log Message:
------------
JRUBY_RACK-8: adjust LOAD_PATH if jruby_home detection failed in the current 
environment
JRUBY_RACK-27: Ensure to chomp trailing slash on paths
Add spec for trailing slash chomp


Revisions:
----------
cbb474cb668d31d90460f75424db92a35be2b688
89229896666868e4573eafaeb299c16fe51a3861
d23f7789b51a03f6150d5aa9ee817d8eeb9a1a71


Modified Paths:
---------------
src/main/ruby/jruby/rack/booter.rb
src/main/ruby/jruby/rack/app_layout.rb
src/spec/ruby/jruby/rack/booter_spec.rb


Diffs:
------
diff --git a/src/main/ruby/jruby/rack/booter.rb 
b/src/main/ruby/jruby/rack/booter.rb
index e2482f8..c2c3605 100644
--- a/src/main/ruby/jruby/rack/booter.rb
+++ b/src/main/ruby/jruby/rack/booter.rb
@@ -16,6 +16,7 @@ module JRuby::Rack
     end
 
     def boot!
+      adjust_load_path
       ENV['RACK_ENV'] = @rack_env
       ENV['GEM_PATH'] = layout.gem_path
       layout.change_working_directory if 
layout.respond_to?(:change_working_directory)
@@ -57,5 +58,16 @@ module JRuby::Rack
     def silence_warnings(&block)
       JRuby::Rack.silence_warnings(&block)
     end
+
+    # http://kenai.com/jira/browse/JRUBY_RACK-8: If some containers do
+    # not allow proper detection of jruby.home, fall back to this
+    def adjust_load_path
+      require 'jruby'
+      if JRuby.runtime.instance_config.jruby_home == 
java.lang.System.getProperty('java.io.tmpdir')
+        $LOAD_PATH << 'META-INF/jruby.home/lib/ruby/site_ruby/1.8'
+        $LOAD_PATH << 'META-INF/jruby.home/lib/ruby/1.8'
+        $LOAD_PATH << 'META-INF/jruby.home/lib/ruby/site_ruby/shared'
+      end
+    end
   end
 end
diff --git a/src/main/ruby/jruby/rack/app_layout.rb 
b/src/main/ruby/jruby/rack/app_layout.rb
index 1ef4201..293e824 100644
--- a/src/main/ruby/jruby/rack/app_layout.rb
+++ b/src/main/ruby/jruby/rack/app_layout.rb
@@ -30,8 +30,11 @@ module JRuby
 
       def real_path(path)
         rpath = @rack_context.getRealPath(path)
-        # protect windows paths from backrefs
-        rpath.sub!(/\\([0-9])/, '\\\\\\\\\1') if rpath
+        if rpath
+          # protect windows paths from backrefs
+          rpath.sub!(/\\([0-9])/, '\\\\\\\\\1')
+          rpath.chomp!('/')
+        end
         rpath
       end
diff --git a/src/spec/ruby/jruby/rack/booter_spec.rb 
b/src/spec/ruby/jruby/rack/booter_spec.rb
index b8b5ca1..2c8954f 100644
--- a/src/spec/ruby/jruby/rack/booter_spec.rb
+++ b/src/spec/ruby/jruby/rack/booter_spec.rb
@@ -34,6 +34,12 @@ describe JRuby::Rack::Booter do
     @booter.public_path.should == "."
   end
 
+  it "should chomp trailing slashes from paths" do
+    @rack_context.should_receive(:getRealPath).with("/").and_return 
"/hello/there/"
+    create_booter.boot!
+    @booter.public_path.should == "/hello/there"
+  end
+
   it "should determine the gem path from the gem.path init parameter" do
     
@rack_context.should_receive(:getInitParameter).with("gem.path").and_return 
"/blah"
     @rack_context.should_receive(:getRealPath).with("/blah").and_return "."




[jruby-rack~main:d23f7789] Add spec for trailing slash chomp

nicksieger 03/31/2010
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close