Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

asset_tag_helper.rb expression bug in compute_public_path

#1085

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.

Reported by mctozzy · September 21st, 2008 @ 01:55 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. madlep
    madlep

    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.

    September 26th, 2008 @ 06:49 AM

  2. madlep
    madlep

    *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

    September 26th, 2008 @ 06:51 AM

  3. madlep
    madlep
    • 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 "."

    October 5th, 2008 @ 07:03 AM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [8e50f0f96ef53ee8cc7ffa86ce0e71cc357b2b6c]) Fix image_tag behavior on windows. [#1085 asset_tag_helper.rb expression bug in compute_public_path state:resolved]

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

    October 6th, 2008 @ 11:44 PM