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

Issue when using unicode in variables #52

Open
paroxp opened this issue Jun 15, 2017 · 6 comments
Open

Issue when using unicode in variables #52

paroxp opened this issue Jun 15, 2017 · 6 comments

Comments

@paroxp
Copy link

paroxp commented Jun 15, 2017

What

I stumbled upon an issue, where a unicode character that is in a variable, will not be compiled properly, but turned into a square instead.

It's particularly annoying, when working with sprites or something like font-awesome.

Test case

package main

import (
	"bytes"
	"fmt"
	"strings"
	"testing"

	libsass "github.com/wellington/go-libsass"
)

func TestUnicodeCharInVar(t *testing.T) {
	var dst bytes.Buffer

	src := bytes.NewBufferString(`
$test: "\f00d";

p {
	a {
		content: $test;
	}

	b {
		content: "\f00c";
	}
}
`)

	comp, err := libsass.New(&dst, src)
	if err != nil {
		t.Error("Expected to create compiler successfully")
	}

	err = comp.Run()
	if err != nil {
		t.Error("Expected to run the compiler successfully")
	}

	css := dst.String()

	if !strings.Contains(css, "\\f00c") { // This one is passing
		t.Errorf("Expected to find `%s` in compiled css", "\\f00c")
	}

	if !strings.Contains(css, "\\f00d") { // This one isn't
		t.Errorf("Expected to find `%s` in compiled css", "\\f00d")
	}

	fmt.Println(dst.String())
}

Output

→ go test custom_test.go
@charset "UTF-8";
p a {
  content: ""; }

p b {
  content: "\f00c"; }

--- FAIL: TestUnicodeCharInVar (0.00s)
        custom_test.go:46: Expected to find `\f00d` in compiled css
FAIL
FAIL    command-line-arguments  0.005s
paroxp added a commit to paroxp/rafalp that referenced this issue Jun 17, 2017
Font-awesome although is in fact awesome, is massive. We're not using
every single icon, in fact, we're using only 4 out of 675... It's
unreasonable to keep using it.

We're preparing our own font and styling, to keep the same approach,
with much less MB to be loaded.

It also, fixes the issue with [go-libsas][1] we're having, allowing us
to move forward with the application.

[1]: wellington/go-libsass#52
paroxp added a commit to paroxp/rafalp that referenced this issue Jun 17, 2017
Font-awesome although is in fact awesome, is massive. We're not using
every single icon, in fact, we're using only 4 out of 675... It's
unreasonable to keep using it.

We're preparing our own font and styling, to keep the same approach,
with much less MB to be loaded.

It also, fixes the issue with [go-libsas][1] we're having, allowing us
to move forward with the application.

[1]: wellington/go-libsass#52
paroxp added a commit to paroxp/rafalp that referenced this issue Jun 17, 2017
Font-awesome although is in fact awesome, is massive. We're not using
every single icon, in fact, we're using only 4 out of 675... It's
unreasonable to keep using it.

We're preparing our own font and styling, to keep the same approach,
with much less MB to be loaded.

It also, fixes the issue with [go-libsas][1] we're having, allowing us
to move forward with the application.

[1]: wellington/go-libsass#52
@drewwells
Copy link
Member

That is annoying. I don't believe go-libsass is causing this issue, but I'm taking a look

@drewwells
Copy link
Member

Also thanks for posting a fully working, reproducible unit test. You are the best 💯 🎆

@drewwells
Copy link
Member

So interesting, the Ruby Sass maintainers seem to be resistant to address this problem which cropped up in a minor release of 3.4. You can force the expected ascii output by doing this: https://www.sassmeister.com/gist/22743e406eeb3744988c

If possible, I'd recommend moving away from storing escaped unicode in variables. It's unlikely Sass will remedy this issue. There's no work been done to let developers dictate the encoding of Sass output.

Long story here: sass/sass#1395

@drewwells
Copy link
Member

This may work as well, content: unquote("\\")+$contentvar;. Either way it requires removing the unicode prefix from all variables.

@paroxp
Copy link
Author

paroxp commented Jun 17, 2017

Nice research work. Thanks :)

It's weird, as the same code worked totally fine with gulp/grunt. I doubt that the need of modifying an external library (like font-awesome) will be a common thing for people.

I've worked around the issue by not using font-awesome, which I couldn't really justify.

I'm happy for the issue being resolved, as it is clearly not related to the package itself.

Thanks again for investing time in this!

@kimek
Copy link

kimek commented Sep 21, 2017

@drewwells
content: unquote("\\")+$contentvar;
works however
content: unquote("\"")+unquote("\\")+$contentvar+unquote("\"");
doesn't. Is there any chance to turn off UTF-8 in sass?
As I see from sass/sass#1395 there is no ASCII 'force mode' yet ;/

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

No branches or pull requests

3 participants