Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault if a function definition has a css comment #646

Closed
soulan opened this issue Nov 13, 2014 · 5 comments · Fixed by #836
Closed

Segfault if a function definition has a css comment #646

soulan opened this issue Nov 13, 2014 · 5 comments · Fixed by #836

Comments

@soulan
Copy link

soulan commented Nov 13, 2014

@function text-contrast($bg-color, $dark-text: $dark-text-color, $light-text: $light-text-color) {
/*
$bg-brightness: round(red($bg-color) * 0.3) + (green($bg-color) * 0.59) + (blue($bg-color) * 0.11);
@if abs($bg-brightness) < 200 {
    @return $light-text;
} @else {
    @return $dark-text;
}
*/

@if use-dark-text($bg-color){
    @return $dark-text;
} @else {
    @return $light-text;
}

/*
$color-brightness: round((red($bg-color) * 300) + (green($bg-color) * 590) + (blue($bg-color) * 110) / 1000);
$light-text-brightness: round((red($light-text) * 300) + (green($light-text) * 590) + (blue($light-text) * 110) / 1000);
$dark-text-brightness: round((red($dark-text) * 300) + (green($dark-text) * 590) + (blue($dark-text) * 110) / 1000);

@if abs($color-brightness - $light-text-brightness) > abs($color-brightness - $dark-text-brightness) {
    @return $light-text;
} @else {
    @return $dark-text;
}
*/
}

@mixin contrasted-important($background-color, $dark-text: $dark-text-color, $light-text: $light-text-color){
background-color: $background-color !important;
color: text-contrast($background-color, $dark-text, $light-text) !important;
}

I've got these 2 mixins, when I call contrasted-important in this setup I get a segemntation fault

@mixin contrasted-important($background-color, $dark-text: $dark-text-color, $light-text: $light-text-color){
background-color: $background-color !important;
color: text-contrast($background-color, $dark-text, $light-text);
}

and in this setup the value of color gets

color: /*
$bg-brightness: round(red($bg-color) * 0.3) + (green($bg-color) * 0.59) + (blue($bg-color) * 0.11);
@if abs($bg-brightness) < 200 {
    @return $light-text;
} @else {
    @return $dark-text;
}
*/;
@xzyfer
Copy link
Contributor

xzyfer commented Dec 9, 2014

This is because css style comments /* */ are still parsed (somewhat). The errors described are likely due to the commented out code being invalid sass. Ideally we would fail gracefully though.

If you want to truly comment sass code you need to use sass line comments //.

@xzyfer
Copy link
Contributor

xzyfer commented Dec 9, 2014

Sassmeister gist for reference: http://sassmeister.com/gist/b83650c20ec46ac1246b

@xzyfer
Copy link
Contributor

xzyfer commented Jan 12, 2015

Reduced test case

@function foo() {
  /* $bar: 1; */
 @return true;
}

a {
  a: foo();
}

This cases Libsass to hang indefinitely.

@xzyfer xzyfer changed the title Comment Section in function returned + segfault Segfault if a function definition has a css comment Jan 12, 2015
@xzyfer
Copy link
Contributor

xzyfer commented Jan 12, 2015

Spec added sass/sass-spec#241.

@xzyfer
Copy link
Contributor

xzyfer commented Jan 12, 2015

This is fixed and will be in 3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants