This project is archived and is in readonly mode.

#1085 ✓resolved
mctozzy

asset_tag_helper.rb expression bug in compute_public_path

Reported by mctozzy | September 21st, 2008 @ 01:55 PM | in 2.x

There is a line of code that has been modified since rails 2.0.2 which reads like this:


              source += ".#{ext}" if ext && File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, dir, "#{source}.#{ext}"))

This is producing the wrong result on jruby, (and I'm not sure why it doesn't also on MRI) but there is a precedence problem due to missing brackets?

I altered it to read:


              source += ".#{ext}" if ext && (File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, dir, "#{source}.#{ext}")))

This seemed to fix the problem.

Comments and changes to this ticket

  • madlep

    madlep September 26th, 2008 @ 06:49 AM

    I had exactly the same problem at about the same time.

    Problem occurs for me using JRuby 1.1.4 and MRI 1.8.7 on Windows XP, but was fine using both on OS X Leopard.

    Seems the behaviour of File.exist? is different on different OSes in regard to handling file names with a trailing space - as compute_public_path does.

    I struct this when #image_tag called as image_tag("myimage.png") would generate an img tag with a src attribute of "/images/myimage.png.?1142164270" (note the extra . after png). This only occurs on windows.

    I only noticed this because a couple of other devs were running on WEBrick for development, and this refuses to serve up the image. Mongrel seems fine with it though.

  • madlep

    madlep September 26th, 2008 @ 06:51 AM

    *oops, I mean "trailing full stop" as opposed to "trailing space" in previous comment - which compute_public_path tries if ext is nil (as it is in the case of when compute_public_path is called as part of image_tag

  • madlep

    madlep October 5th, 2008 @ 07:03 AM

    • Tag changed from 2.1, actionpack, bug to 2.1, actionpack, action_view, bug, patch

    patch attached that incorporates mctozzy's fix with tests.

    Basically the root cause is a bug with the precedence ordering in #missing_extension? when #image_tag is called.

    The logic should never do the other checks if the extension is nil (as it is in the case of image_tag), but with the existing code it was. This produced an incorrect image URL when running rails on Windows due to a quirk with the way windows handles File.exist? for file names ending with a "."

  • Repository

    Repository October 6th, 2008 @ 11:44 PM

    • State changed from “new” to “resolved”

    (from [8e50f0f96ef53ee8cc7ffa86ce0e71cc357b2b6c]) Fix image_tag behavior on windows. [#1085 state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages