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.

Windows File Loading

#440

After upgrading to Rails 2.1.0 I noticed that when running on Windows XP Pro I could no longer see icons on the UI. All is well when running on Linux.

Viewing the source in the browser revealed that my image file names contained an extra .

For some reason, Windows accepts the file name foo.png. (with a trailing .) as equivalent to foo.png (no trailing .). On Windows, File.exist?("foo.png.") returns true if foo.png exists.

This causes a problem AssetTagHelper::compute_public_path. This line:

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

will add a . to source if ext is nil because the || clause returns true on windows.

A fix that seems to work is to rework the logic with a couple of extra brackets which probably reflect the intended behavior of the statement:

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

After the change, a nil ext drops out immediately.

Reported by Ross MacCharles · June 17th, 2008 @ 09:56 PM

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. rasmus
    rasmus
    • Tag set to 2.1, actionpack, bug

    Hi,

    We came across the same problem, and thought that the correct solution maybe was to replace the OR with an AND. With the line resulting to:

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

    August 1st, 2008 @ 12:08 PM

  2. Andreas
    Andreas

    The patch above is incorrect, it breaks javascript_include_tag for js being served by a controller. I believe the intended logic is to check that ext is defined for both statements separately (that works anyway):

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

    August 4th, 2008 @ 05:53 PM

  3. Andreas
    Andreas

    I made a pull request for this, but it told me to attach a git formatted patch instead. So here:

    diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack index ed33f08..9177dc1 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -485,7 +485,7 @@ module ActionView

           source = COMPUTED_PUBLIC_PATHS.fetch(cache_key) do
             begin
    
    
    •        source += ".#{ext}" if ext && File.extname(source).blank? || File
      
      
    •        source += ".#{ext}" if (ext && File.extname(source).blank?) || (e
      
             if source =~ %r{^[-a-z]+://}
               source
      
      

    September 5th, 2008 @ 01:27 PM

  4. Andreas
    Andreas

    Oops, here's the patch as an attachmen :)

    September 5th, 2008 @ 01:28 PM

  5. Frederick Cheung
    Frederick Cheung
    • State changed from new to duplicate

    December 12th, 2008 @ 02:12 PM