Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Simultaenous use of manifest and a magic comment #7455

Closed
Exoth opened this Issue · 19 comments

8 participants

@Exoth

Rails 3.2.8.

I've got a .js.erb file where I need to use both manifest and a magic comment, and I would assume that this should work:

<%# encoding: utf-8 %>
//= require some_stuff

or at least this should work:

<%# encoding: utf-8 %>//= require some_stuff

as erb processing has to be done before js processing resulting in js getting simple

//= require some_stuff

But for some strange reason manifest directives don't work and are just included as text. Putting manifest definitions the first and encoding the second enables manifest but disables encoding.

@gaurish

If I can understant correctly,
After ERB processing is done, the magic comment still remain on the top of the file. While doing the js prepossing, sprockets expects the //= require style comments to start from very first line. if it find something else like blank lines or some other code, it stops looking for any //= require in that file & just renders the complete file as text without any further modifications.

Correct?

@steveklabnik
Collaborator

That seems like it might be the issue, yes. I forget exactly how all this works, to be honest, but that sounds about right.

@gaurish

Well, we can add a simple conditional in sprockets code for magic comment. It would check is first line is a magic comment specifying the encoding, if yes then would scan rest of the file for any //= require until blank lines are encountered.

Let me know if this is the correct approach to fix or there is a better way. I will try to write patch over the weekend :)

@steveklabnik
Collaborator

Discussing this with @tenderlove, apparently there are bugs in jsc when you include Unicode in your javascript. Mountain Lion seems to fix them, but there may be dragons down this road.

@steveklabnik
Collaborator

Why are you including the magic comment, by the way? Rails should serve everything with a utf8 encoding by default.

@gaurish

That we will have to ask @Exoth. I was just trying to help fix a bug(if any)

btw, what is jsc?

[edit]
Nvm, found it but how is this relevant to rails? Do we use it to run tests? or something else?

@steveklabnik
Collaborator

Since Rails has the 'use whatever Javascript runtime' code in it, you may get intermittent failures due to environmental differences :/

@Exoth

Later in this fils is a 'render' of a file with some special symbols. Until I have the magic comment, it gives me an error of incompatibility with ASCII.

@steveklabnik
Collaborator

Ahh, yes, processing in plain ruby outside of Rails would make this happen. Just wondering; obviously, that should work somehow.

@parndt

Is this really a Rails issue or a Sprockets issue? Is it still relevant?

@Exoth

The last time I checked the problem was still here.

@steveklabnik
Collaborator

It's part of Rails for 3.2, it's part of sprockets-rails for Rails 4.

@Exoth

Very good. Looking forward for the Rails 4 release.

@tgaff

I've got the same problem. One workaround is to run ruby with -Ku to avoid needing the magic comment at all.

@gaurish

Ruby 2.0 has UTF-8 default encoding, which may make magic comments omissible & fix this issue.

@JonRowe

@gaurish except that while Rails supports 1.9.3 that isn't an acceptable fix ;) has anyone made any progress on this? [triage]

@tgaff

I used something like this temporarily: tgaff/sprockets@a098b35

@Exoth Exoth added the stale label
@rafaelfranca
Owner

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

@rails-bot rails-bot closed this
@rails-bot
Collaborator

This issue has been automatically closed because of inactivity.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.