Skip to content

Commit

Permalink
Fix an @extend edge-case crash.
Browse files Browse the repository at this point in the history
Closes #1656
  • Loading branch information
nex3 committed Feb 27, 2015
1 parent 4e41909 commit 787b6ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@

* `@keyframes` rules are now converted from CSS properly.

* Extending a selector that contains a non-final pseudo-class no longer crashes.

## 3.4.12 (13 February 2015)

[Tagged on GitHub](https://github.com/sass/sass/releases/tag/3.4.12).
Expand Down
9 changes: 3 additions & 6 deletions lib/sass/selector/simple.rb
Expand Up @@ -72,12 +72,9 @@ def eql?(other)
def unify(sels)
return sels if sels.any? {|sel2| eql?(sel2)}
sels_with_ix = Sass::Util.enum_with_index(sels)
_, i =
if is_a?(Pseudo)
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && (sels.last.type == :element)}
else
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo)}
end
if !is_a?(Pseudo) || (sels.last.is_a?(Pseudo) && sels.last.type == :element)
_, i = sels_with_ix.find {|sel, _| sel.is_a?(Pseudo)}
end
return sels + [self] unless i
sels[0...i] + [self] + sels[i..-1]
end
Expand Down
10 changes: 10 additions & 0 deletions test/sass/extend_test.rb
Expand Up @@ -1338,6 +1338,16 @@ def test_optional_extend_succeeds_when_extension_fails

# Regression Tests

def test_extend_with_middle_pseudo
assert_equal(<<CSS, render(<<SCSS))
.btn:active.focus, :active.focus:before {
a: b; }
CSS
.btn:active.focus {a: b}
:before {@extend .btn}
SCSS
end

def test_extend_parent_selector_suffix
assert_equal <<CSS, render(<<SCSS)
.a-b, .c {
Expand Down

0 comments on commit 787b6ef

Please sign in to comment.