Permalink
Browse files

Fix for strange paths like /path/to/project/./ and /path/to/project/../

  • Loading branch information...
1 parent 1a09ef7 commit 8b66e2518c2b28c2a859c4c787650d94609ae36e @chriseppstein chriseppstein committed Jun 12, 2011
Showing with 14 additions and 11 deletions.
  1. +3 −4 lib/sass/importers/filesystem.rb
  2. +11 −7 test/sass/engine_test.rb
@@ -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
@@ -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
View
@@ -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.",
@@ -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

0 comments on commit 8b66e25

Please sign in to comment.