Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionView::Template::Error (invalid regexp character): Error on newly created rails app on Windows #38

Closed
KapilSachdev opened this issue May 17, 2018 · 10 comments

Comments

@KapilSachdev
Copy link

KapilSachdev commented May 17, 2018

Hi @judofyr
The default JavaScript engine on Windows is now duktape.

The issue occurs when using the gem bootstrap-rubygem with duktape as JS runtime. Changing EXECJS_RUNTIME to any other resolves the issue.

# In `config/boot.rb`, changes the ExecJS runtime from Duktape to Node.
ENV['EXECJS_RUNTIME'] = 'Node

So looks like duktape has some compilation issues.

Steps to reproduce

  • Use Windows-10
  • Install RubyInstaller-2.5.1-1 (inkluding MSYS2 development tools)
  • Then run:
gem install rails
rails new myapp
cd myapp
# Add the bootstrap gem to the Gemfile
gem 'bootstrap', '~> 4.1.1'
#  Import Bootstrap styles in app/assets/stylesheets/application.scss
@import "bootstrap";
# Create a controller and run server
rails g controller welcome index
rails s

Now Browse to http://localhost:3000/welcome/index

Expected behavior

It should show the index page with bootstrap css and js included.

Actual behavior

It raises the error

ActionView::Template::Error (invalid regexp character):
     5:     <%= csrf_meta_tags %>
     6:     <%= csp_meta_tag %>
     7:
     8:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
     9:     <%# <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> %>
    10:   </head>
    11:

(execjs):24531
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__393616251_122130440'

System configuration

Rails version: 5.2.0
Ruby version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32]

Logging bootstrap-rubygem issue.

Including @larskanis due to PR

Thanks

@svaarala
Copy link

@KapilSachdev Could you provide the source line producing the error?

@KapilSachdev
Copy link
Author

@svaarala , stylesheet_link_tag and javascript_include_tag both cause this issue. Hope this helps.

ActionView::Template::Error (invalid regexp character):
     5:     <%= csrf_meta_tags %>
     6:     <%= csp_meta_tag %>
     7:
     8:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
     9:     <% <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> %>
    10:   </head>
    11:

(execjs):24531
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__393616251_122130440'

(updated the above description too)

@svaarala
Copy link

But that's not javascript source line causing the issue ("invalid regexp character"). So I'm basically looking for the offending RegExp.

@KapilSachdev
Copy link
Author

Well I haven't dig into that as I moved on to other stuff and that's why reported here.
I will look into it and inform.
Meanwhile, if you can have a look at the bootstrap gem would be great.

@KapilSachdev
Copy link
Author

Hi @svaarala,

I think i found it.

function parseSourceMapInput(str) {
  return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
}

When I execute this (using execjs with duktape), I could reproduce invalid regexp character error.

ExecJS.compile(source) # source being the JS

@judofyr
Copy link
Owner

judofyr commented May 18, 2018

Minimal test case:

Duktape::Context.new.eval_string('/]/.source')

The regexp /]/ seems to work nicely in Chrome.

@svaarala
Copy link

The technical background is that e.g. /]/ regexp syntax is only recommended for legacy environments, see https://www.ecma-international.org/ecma-262/6.0/#sec-additional-ecmascript-features-for-web-browsers. In practice much of the existing Javascript just assumes the browser-like legacy support.

Duktape supports parts of the legacy Annex B regexp syntax, but not all of it. However, /]/ should work at least in 2.0.0 and above:

((o) Duktape [linenoise] 2.0.0 (v2.0.0)
duk> r = /]/;
= {}
duk> r.exec(']')
= ["]"]

@judofyr
Copy link
Owner

judofyr commented May 19, 2018

I guess I should release Duktape 2.0 then

judofyr added a commit that referenced this issue May 21, 2018
@judofyr
Copy link
Owner

judofyr commented May 21, 2018

Duktape.rb 2.0.1 is now released and things should work as expected.

@KapilSachdev
Copy link
Author

@judofyr, Encountering new issue after the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants