jruby regex different on windows from os x?
i've got a jruby regex that i'm printing in rails:
@@private = /somethingthatshouldnevermatch/
def secure?
pu开发者_StackOverflowts "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?
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.
精彩评论