0

i've got a jruby regex that i'm printing in rails:

@@private = /somethingthatshouldnevermatch/
def secure?
  puts "security test(#{action_name}/#{@@private}: #{@@private.match(action_name).nil?.to_s}"
  action_name =~ @@private
end

on os x, using WEBRick and jruby, this prints

security test(index/(?-mix:somethingthatshouldnevermatch):

on windows, this prints

security test(index/?-mix:):

i used warbler to wrap this up into a war and drop it into a tomcat directory on windows.

what gives?

edit - moar info

issue turned out to be an environment setting. warbler defaults to 'production', instead of dev. however, i still don't understand why it behaved this way.

more specifics - this is the way i'm implementing security in my RoR app. i have a secure? method on the ApplicationController, and override the value of @@private in subclasses. it looks like with the environment set to production, the regex stopped getting initialized in the base class. it was \\ for everyone, which caused the rest of my issues.

ideas?

kolosy
  • 3,029
  • 3
  • 29
  • 48
  • Your code looks like it does something different than the example output you give. It might be best if you narrow your problem down to a simple example that could be run in `irb`, so we can more easily see what's going on, and post the actual output you get from that on each system. – Brian Campbell Sep 10 '10 at 21:30
  • 'twas a typo. i've updated the code since then. – kolosy Sep 10 '10 at 21:33

1 Answers1

0

I'd suggest peeling away the layers to get to the root cause (or rule out what you think is the cause). In this case, peel away warbler, rails, etc and make your logic runnable in jirb (as Brian suggested).

I modified your code slightly do I could run it in jirb as follows:

def secure?(action_name)
    puts "security test(#{action_name}/#{@@private}:#@@private.match(action_name).nil?.to_s}"
    action_name =~ @@private
end

calling secure?("index") returned:

security test(index/(?-mix:somethingthatshouldnevermatch): true

Which I understand is what you expect, but not what you're getting.

If I had to guess, I'd say the variable action_name is not what your expecting. My rails knowledge is a bit rusty, and I cannot see this variable described in the Rails3 API doc. Possibly, it's not part of the formal public API?

Which version of jruby and rails are you running? I am running jruby 1.5.1 on Windows XP.

Robert Brown
  • 10,888
  • 7
  • 34
  • 40
  • how would the value of action_name affect the value of the regex object? that's the issue here - the regex isn't being set. action_name is a RoR parameter that tells you the name of the invoked action. – kolosy Sep 15 '10 at 17:37
  • True, true... Can you try use a local variable instead of class variable? – Robert Brown Sep 16 '10 at 07:04