Skip to content

Commit

Permalink
Fix for strange paths like /path/to/project/./ and /path/to/project/../
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Jun 12, 2011
1 parent 1a09ef7 commit 8b66e25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 3 additions & 4 deletions lib/sass/importers/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Filesystem < Base
# @param root [String] The root path.
# This importer will import files relative to this path.
def initialize(root)
@root = root
@root = File.expand_path(root)
end

# @see Base#find_relative
Expand Down Expand Up @@ -58,9 +58,8 @@ def eql?(other)
# If a full uri is passed, this removes the root from it
# otherwise returns the name unchanged
def remove_root(name)
root = @root.end_with?('/') ? @root : @root + '/'
if name.index(root) == 0
name[root.length..-1]
if name.index(@root + "/") == 0
name[(@root.length + 1)..-1]
else
name
end
Expand Down
18 changes: 11 additions & 7 deletions test/sass/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ class SassEngineTest < Test::Unit::TestCase
"& a\n :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
"a\n :b\n c" => "Illegal nesting: Only properties may be nested beneath properties.",
"$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
"@import foo.sass" => "File to import not found or unreadable: foo.sass.",
"$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
"@import foo.sass" => <<MSG,
File to import not found or unreadable: foo.sass.
Load path: .
MSG
"@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
"foo\n @import foo.css" => "CSS import directives may only be used at the root of a document.",
"@if true\n @import foo" => "Import directives may not be used within control directives or mixins.",
Expand Down Expand Up @@ -579,12 +574,21 @@ def test_sass_pathname_import
assert File.exists?(sassc_file)
end

def test_nonexistent_import
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) do
File to import not found or unreadable: nonexistent.sass.
Load path: #{Dir.pwd}
ERR
render("@import nonexistent.sass")
end
end

def test_nonexistent_extensionless_import
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) do
File to import not found or unreadable: nonexistent.
Load path: .
Load path: #{Dir.pwd}
ERR
assert_equal("@import url(nonexistent.css);\n", render("@import nonexistent"))
render("@import nonexistent")
end
end

Expand Down

0 comments on commit 8b66e25

Please sign in to comment.