This project is archived and is in readonly mode.

#440 ✓duplicate
Ross MacCharles

Windows File Loading

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

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.

Comments and changes to this ticket

  • rasmus

    rasmus August 1st, 2008 @ 12:08 PM

    • 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}"))

  • Andreas

    Andreas August 4th, 2008 @ 05:53 PM

    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}")))
    
  • Andreas

    Andreas September 5th, 2008 @ 01:27 PM

    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
      
      
  • Andreas

    Andreas September 5th, 2008 @ 01:28 PM

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

  • Frederick Cheung

    Frederick Cheung December 12th, 2008 @ 02:12 PM

    • State changed from “new” to “duplicate”

    Duplicate of #1085, which was resolved

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

Pages