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

error on UTF-8 with sugnature files #22

Closed
Igorbek opened this issue Jul 6, 2012 · 17 comments
Closed

error on UTF-8 with sugnature files #22

Igorbek opened this issue Jul 6, 2012 · 17 comments

Comments

@Igorbek
Copy link
Contributor

Igorbek commented Jul 6, 2012

When trying to process file with UTF-8 with signature (BOM) encoding, getting error:

ERROR -- filename, line 1: invalid top-level expression

@HamptonMakes
Copy link
Member

Can you attach a sample failing file?

  • Hampton

On Jul 6, 2012, at 10:27 AM, [email protected] wrote:

When trying to process file with UTF-8 with signature (BOM) encoding, getting error:

ERROR -- filename, line 1: invalid top-level expression


Reply to this email directly or view it on GitHub:
#22

@Igorbek
Copy link
Contributor Author

Igorbek commented Jul 6, 2012

Sure!
...ah. How to attach a file here? Can't find ((

@Igorbek
Copy link
Contributor Author

Igorbek commented Jul 6, 2012

I've sent it via email.

I writing the .Net wrapper for libsass, so I compiled the sources with MS C++ compiler in CLR mode.
The error occured when source file specified by filename (in sass_compile_file), or if it specified by @import directive.

@emagnier
Copy link

I'm using Sassc on Windows, and with many files created by Visual Studio I get the same error: "invalid top-level expression".

I made the test with the latest versions of libsass and sassc.

Here is an example of a file that does not compile:
http://files.etiennemagnier.com/public/test-encoding.zip

Thanks,
Etienne.

@craigbarnes
Copy link
Contributor

The UTF-8 BOM is 0xEF 0xBB 0xBF. No other BOM begins 0xEF, so a simple fix would be to check if byte 0 is 0xEF and if so, drop the first 3 bytes.

@emagnier
Copy link

emagnier commented Mar 3, 2013

Thanks Craigbarnes for your comment!

This problem prevents me from using Sassc on several of my projects, and unfortunately I don't have an enough good level in C++ to provide a fix.
I keep my fingers crossed hoping this issue will be solved soon ;-)

@craigbarnes
Copy link
Contributor

If you're using Visual Studio, I think you can set the encoding to UTF-8 without signature to save without a BOM.

@emagnier
Copy link

emagnier commented Mar 3, 2013

Yes, but as the default files created by Visual Studio are with BOM, it will be dificult to ask all my team members to manually change the encoding each time they create a new scss file.
And if I change the encoding of the existing scss files, I will break the "compare" and "merge" features of our source control (TFS) with the previous versions & branches.

@akhleung
Copy link

Just check for those three bytes? No problem.

@emagnier
Copy link

emagnier commented May 2, 2013

Hi Aaron,
I know you are very busy, but are you going to have time to fix this one?
Because of this bug I still can't consider using LibSass on our projects on Windows.
Thanks.

@akhleung
Copy link

akhleung commented May 3, 2013

I'll work on this one right now.

@akhleung
Copy link

akhleung commented May 4, 2013

All right, I added checks for all of the BOMs listed on the Wikipedia page:

http://en.wikipedia.org/wiki/Byte_order_mark

Please let me know whether or not it works for you.

@emagnier
Copy link

emagnier commented May 7, 2013

I did a test with your latest commit, and all the encoding errors have disappeared.
A great thanks for your work, it's really appreciated! 👍

@akhleung akhleung closed this as completed Jun 9, 2013
@techniq
Copy link

techniq commented Mar 4, 2014

I ran into this issue today using gulp-sass/node-sass/libsass that was due to creating the .scss file in Visual Studio 2012, which created a UTF-8 encoded file. Opening the file in notepad and changing the encoding to ANSI solved the invalid top-level expression error for me.

@QuLogic
Copy link
Contributor

QuLogic commented Mar 4, 2014

The top-level expression is probably the BOM, so it sounds like gulp-sass/node-sass are using an older version of libsass. You might be able to save it as UTF-8-without-BOM and that might work. No guarantees that non-Latin characters might not be a problem without updating libsass though.

@mgreter
Copy link
Contributor

mgreter commented Mar 4, 2014

This might have something to do with the pull request #283. IMO this change makes the parser to recognise the BOM as alpha characters and therefore seeing it as an expression? But I guess libsass should just "throw away" the BOM once it has determined there is one (this is also very true for imports, as you do not want the BOM to be inserted in the source document). But from the age of this bug I would have guessed that this has already been solved?

@jbutko
Copy link

jbutko commented Mar 4, 2014

Got this same error today. Found out I had a redundant expression in my gruntfile.js file: 'css/ie.css': 'css/ie.scss' Deleted this and now it works like a charm. So always double check if you are referencing only real files.

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

9 participants