jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-41

ajax_scaffold generator fails due to regular expression 'dot' matching not picking up \r characters

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.0
  • Fix Version/s: JRuby 0.9.1
  • Component/s: Interpreter
  • Labels:
    None
  • Environment:
    JRuby 0.9.0 with Rails 1.1.4

Description

C:\jruby-0.9.0\cookbook>c:\jruby-0.9.0\bin\jruby script/generate ajax_scaffold recipe
C:/jruby-0.9.0/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/oracle_adapter.rb:118 warning: (...) interpreted as grouped expression
exists test/unit/
exists test/fixtures/
exists app/controllers/
exists app/helpers/
create app/views/recipes
exists app/views/layouts/
exists public/images
exists test/functional/
create app/models/recipe.rb
create test/unit/recipe_test.rb
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    jruby-41.patch
    29/Sep/06 2:47 PM
    1.0 kB
    Charles Oliver Nutter

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Miguel Covarrubias added a comment - 25/Jul/06 9:02 AM

I looked at this a bit and it appears to be a problem related to regular expressions and line terminations. There are a pair of regular expressions in erb.rb that look for start and end tags in a template file, but these seem to make some unfortunate assumptions about line terminators:

stag_reg = /(.*?)(<%%|<%=|<%#|<%-|<%|\n|\z)/
etag_reg = /(.*?)(%%>|-%>|%>|\n|\z)/

The template file 'unit_test.rb' from the ajax_scaffold distribution is opened in binary mode and has Windows '\r\n' line terminators. The '.' in the regular expressions doesn't appear to match the '\r', which eventually leads to the attempted subscripting of nil. Altering these regular expressions to look for '\r\n' in their second groups gets past the problem:

stag_reg = /(.*?)(<%%|<%=|<%#|<%-|<%|\n|\r\n|\z)/
etag_reg = /(.*?)(%%>|-%>|%>|\n|\r\n|\z)/

Probably not an ideal solution...

Also, there's still a problem even after making these changes:

uninitialized constant SO_KEEPALIVE

Show
Miguel Covarrubias added a comment - 25/Jul/06 9:02 AM I looked at this a bit and it appears to be a problem related to regular expressions and line terminations. There are a pair of regular expressions in erb.rb that look for start and end tags in a template file, but these seem to make some unfortunate assumptions about line terminators: stag_reg = /(.*?)(<%%|<%=|<%#|<%-|<%|\n|\z)/ etag_reg = /(.*?)(%%>|-%>|%>|\n|\z)/ The template file 'unit_test.rb' from the ajax_scaffold distribution is opened in binary mode and has Windows '\r\n' line terminators. The '.' in the regular expressions doesn't appear to match the '\r', which eventually leads to the attempted subscripting of nil. Altering these regular expressions to look for '\r\n' in their second groups gets past the problem: stag_reg = /(.*?)(<%%|<%=|<%#|<%-|<%|\n|\r\n|\z)/ etag_reg = /(.*?)(%%>|-%>|%>|\n|\r\n|\z)/ Probably not an ideal solution... Also, there's still a problem even after making these changes: uninitialized constant SO_KEEPALIVE
Hide
Permalink
Miguel Covarrubias added a comment - 25/Jul/06 9:39 PM

Yup, here on the Mac at least the carriage return handling with regular expression dot metachars seems to be the trouble:

In MRI irb:

irb(main):001:0> %r{.}.match("\r")[0]
=> "\r"
irb(main):002:0>


in JRuby jirb:

irb(main):001:0> %r{.}.match("\r")[0]
NoMethodError: undefined method `[]' for nil:NilClass
from (irb):1:in `method_missing'
from (irb):1
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:150:in `eval_input'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:70:in `signal_status'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:189:in `eval_input'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:190:in `loop'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:190:in `catch'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:190:in `eval_input'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:70:in `start'
from /Users/mcovarru/Documents/workspace/jruby/bin/jirb:13:in `catch'
from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:71:in `start'
from /Users/mcovarru/Documents/workspace/jruby/bin/jirb:13
irb(main):002:0>

Show
Miguel Covarrubias added a comment - 25/Jul/06 9:39 PM Yup, here on the Mac at least the carriage return handling with regular expression dot metachars seems to be the trouble: In MRI irb: irb(main):001:0> %r{.}.match("\r")[0] => "\r" irb(main):002:0> in JRuby jirb: irb(main):001:0> %r{.}.match("\r")[0] NoMethodError: undefined method `[]' for nil:NilClass from (irb):1:in `method_missing' from (irb):1 from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:150:in `eval_input' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:70:in `signal_status' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:189:in `eval_input' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:190:in `loop' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:190:in `catch' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:190:in `eval_input' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:70:in `start' from /Users/mcovarru/Documents/workspace/jruby/bin/jirb:13:in `catch' from /Users/mcovarru/Documents/workspace/jruby/lib/ruby/1.8/irb.rb:71:in `start' from /Users/mcovarru/Documents/workspace/jruby/bin/jirb:13 irb(main):002:0>
Hide
Permalink
Charles Oliver Nutter added a comment - 07/Aug/06 9:22 PM

This is likely a duplicate of another bug reported here...

Show
Charles Oliver Nutter added a comment - 07/Aug/06 9:22 PM This is likely a duplicate of another bug reported here...
Hide
Permalink
Charles Oliver Nutter added a comment - 07/Aug/06 9:26 PM

Er, I see this is a regex issue now; renaming as appropriate.

Ola Bini posted a possible fix for this to the list, where we replace . with . plus \r before compiling incoming regex. Java's regex . will never match \r.

Show
Charles Oliver Nutter added a comment - 07/Aug/06 9:26 PM Er, I see this is a regex issue now; renaming as appropriate. Ola Bini posted a possible fix for this to the list, where we replace . with . plus \r before compiling incoming regex. Java's regex . will never match \r.
Hide
Permalink
Charles Oliver Nutter added a comment - 29/Sep/06 1:13 PM

There's another potential fix for this: Pattern.DOTALL. This causes line-terminator characters to be matched by .

So we have a few possible solutions...I'll look into it a bit today.

Show
Charles Oliver Nutter added a comment - 29/Sep/06 1:13 PM There's another potential fix for this: Pattern.DOTALL. This causes line-terminator characters to be matched by . So we have a few possible solutions...I'll look into it a bit today.
Hide
Permalink
Miguel Covarrubias added a comment - 29/Sep/06 1:22 PM

I suspect (but have not confirmed) that Pattern.DOTALL will match '\n', which I don't think we want.

It doesn't seem to have been recorded here before, but there seems to be a duplicate at JRUBY-123 (with a patch).

Show
Miguel Covarrubias added a comment - 29/Sep/06 1:22 PM I suspect (but have not confirmed) that Pattern.DOTALL will match '\n', which I don't think we want. It doesn't seem to have been recorded here before, but there seems to be a duplicate at JRUBY-123 (with a patch).
Hide
Permalink
Charles Oliver Nutter added a comment - 29/Sep/06 1:33 PM

More results:

DOTALL does not do what we need. It causes both \r and \n to be matched by .

However, UNIX_LINES appears to do the trick. It allows \r to be matched by . while \n remains unmatched. This fixes Miguel's very simple case in the 25/Jul/06 09:39 PM comment above, and potentially others.

I'll attach a patch that fixes the two locations where we instantiate regexp. One of those locations (in the AST) may go away soon because it's not doing appropriate checks for unicode flags.

Show
Charles Oliver Nutter added a comment - 29/Sep/06 1:33 PM More results: DOTALL does not do what we need. It causes both \r and \n to be matched by . However, UNIX_LINES appears to do the trick. It allows \r to be matched by . while \n remains unmatched. This fixes Miguel's very simple case in the 25/Jul/06 09:39 PM comment above, and potentially others. I'll attach a patch that fixes the two locations where we instantiate regexp. One of those locations (in the AST) may go away soon because it's not doing appropriate checks for unicode flags.
Hide
Permalink
Miguel Covarrubias added a comment - 29/Sep/06 2:45 PM

Very cool, I never knew about UNIX_LINES. It at least sounds like it should do the trick.

Show
Miguel Covarrubias added a comment - 29/Sep/06 2:45 PM Very cool, I never knew about UNIX_LINES. It at least sounds like it should do the trick.
Hide
Permalink
Charles Oliver Nutter added a comment - 29/Sep/06 2:47 PM

Sets regex to use UNIX_LINES flag so \r will be matched by .

Show
Charles Oliver Nutter added a comment - 29/Sep/06 2:47 PM Sets regex to use UNIX_LINES flag so \r will be matched by .
Hide
Permalink
Charles Oliver Nutter added a comment - 01/Oct/06 4:27 PM

Raphael Gillet has reported that the ajax scaffolding generator is now working well. There appear to be some other issues, but the original regex problem seems to be solved:

Ajax Scaffold generator now works quite well on Ola Bini's test_arj.
Some Ajax functionality is missing. Not sure why yet.

I will mark this bug resolved, and I have recommended that if Raphael can narrow down any additional bugs that he go ahead and report them separately.

Show
Charles Oliver Nutter added a comment - 01/Oct/06 4:27 PM Raphael Gillet has reported that the ajax scaffolding generator is now working well. There appear to be some other issues, but the original regex problem seems to be solved: Ajax Scaffold generator now works quite well on Ola Bini's test_arj. Some Ajax functionality is missing. Not sure why yet. I will mark this bug resolved, and I have recommended that if Raphael can narrow down any additional bugs that he go ahead and report them separately.
Hide
Permalink
Charles Oliver Nutter added a comment - 01/Oct/06 4:27 PM

Resolving as fixed; sometimes the littlest changes make the biggest difference.

Show
Charles Oliver Nutter added a comment - 01/Oct/06 4:27 PM Resolving as fixed; sometimes the littlest changes make the biggest difference.
Hide
Permalink
Charles Oliver Nutter added a comment - 08/Dec/06 12:25 PM

Closing 0.9.1 resolved issues.

Show
Charles Oliver Nutter added a comment - 08/Dec/06 12:25 PM Closing 0.9.1 resolved issues.

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    Raphael Gillett
Vote (0)
Watch (1)

Dates

  • Created:
    24/Jul/06 4:10 PM
    Updated:
    08/Dec/06 12:25 PM
    Resolved:
    01/Oct/06 4:27 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.