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

Fixed assets precompile regex #2876

Merged
merged 1 commit into from Sep 10, 2011
Merged

Fixed assets precompile regex #2876

merged 1 commit into from Sep 10, 2011

Conversation

ay
Copy link
Contributor

@ay ay commented Sep 5, 2011

The original regex was matching things like jquery.min.js and putting a lot of junk (like jquery-#{digest}.min.js) in public/assets/ that shouldn't be there. The new regex matches everything except files ending with .js or .css (as was intended).

@guilleiguaran
Copy link
Member

@alex3 can you provide a test case for this?

@spastorino
Copy link
Contributor

/cc @josh

@rhulse
Copy link

rhulse commented Sep 6, 2011

This pull request is related to bug #1913

The orignal regex appears to want to include files that are not .js or .css files, but as you say is too broad.

@ay
Copy link
Contributor Author

ay commented Sep 6, 2011

@guilleiguaran I just wrote and pushed a test case for this. The commits are squashed into one.

@rhulse
Copy link

rhulse commented Sep 6, 2011

Can I suggest that you add sanity tests for images and the other file types (including with multiple dots) that this is supposed to capture?

@ay
Copy link
Contributor Author

ay commented Sep 6, 2011

@rhulse I think the other tests test for images. Maybe an image named something like happy.face.png?

Also, should I push a new commit or squash it into one again?

@rhulse
Copy link

rhulse commented Sep 6, 2011

I would expect so.

I suggested the extra tests because I spent some time (unsuccessfully) trying to fix that regex! I wonder if it's worth covering off underscores and dashes too. If this breaks there will be a lot of head-scratching and gnashing of teeth. :-)

@spastorino
Copy link
Contributor

@alex3 +1 to rhulse suggestion, please add those tests and I will merge the pull request

@rhulse
Copy link

rhulse commented Sep 6, 2011

suggestions:

  • happy-face.png
  • happy_face.png
  • happy.happy_face.png
  • happy_happy.face.png
  • happy.happy.face.png

And NOT match:

  • .happy.face
  • .anything-with-a-dot-start

:-) !

@ay
Copy link
Contributor Author

ay commented Sep 6, 2011

@rhulse @spastorino All that in one test or a couple of them?

@spastorino
Copy link
Contributor

@alex3 as you find it better, perhaps you can iterate over a bunch of valid / invalid file names checking if they have been precompiled or not

@rhulse
Copy link

rhulse commented Sep 7, 2011

Would it be a appropriate to extract the creation of this array into its own method, which can then include more comprehensive documentation on the intent? It may avoid future issues if there is refactoring.

@ay
Copy link
Contributor Author

ay commented Sep 7, 2011

@spastorino I just pushed a new (squashed) commit with the updated regex and a pretty comprehensive test. I've included all of @rhulse's suggestions in the test.

@rhulse That would probably be better but I think that should be a separate pull request.

@@ -37,7 +37,7 @@ module Rails
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
@assets.paths = []
@assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
@assets.precompile = [ /^[^.].*(\.(?!js$|css$)[^.]+)+\.*$|^[^.](?:(?!\.).)*\.*$/, /application.(css|js)$/ ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gnarly!

Good luck maintaing that regexp, rails core :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, good luck to you too since you're part of the core :P

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, use a regex and now you have two problems. ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I should split that regexp into two, and put each regexp on its own line with a comment explaining what it does?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think putting this in a method on its own would 'minimize' the issue. If maintenance is a concern it could be more verbose in compiling the array.

@josh
Copy link
Contributor

josh commented Sep 7, 2011

Protip: This logic is now apart of rails itself. You can hack it.

https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/assets.rake#L27-31

Maybe allow precompile to accept a Proc or something so you can do File.extname(path) != '.js'.

@ay
Copy link
Contributor Author

ay commented Sep 8, 2011

@josh See most recent commits.

@ay
Copy link
Contributor Author

ay commented Sep 8, 2011

@guilleiguaran Thanks, just pushed a new commit with your suggestion.

@@ -37,7 +37,8 @@ module Rails
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
@assets.paths = []
@assets.precompile = [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
@assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) && path[0] != '.' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why != '.' is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ignore dot files like .gitkeep or something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot files should already be ignored by sprockets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't know that... should I remove the path[0] != '.'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I'll have to change the test too.

@ay
Copy link
Contributor Author

ay commented Sep 8, 2011

Let me know if this is ready for merge and you want me to squash the commits.

@spastorino
Copy link
Contributor

I think this is ready to go, please rebase and squash the commits

@ay
Copy link
Contributor Author

ay commented Sep 8, 2011

@spastorino squashed

@spastorino
Copy link
Contributor

@alex3 the pull request cannot be merged, can you rebase it on top of the current master?

@ay
Copy link
Contributor Author

ay commented Sep 8, 2011

@spastorino done

spastorino added a commit that referenced this pull request Sep 10, 2011
Fixed assets precompile regex
@spastorino spastorino merged commit be24be6 into rails:master Sep 10, 2011
spastorino added a commit that referenced this pull request Sep 10, 2011
Fixed assets precompile regex
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

Successfully merging this pull request may close these issues.

None yet

5 participants