Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Conversation

@mgreter
Copy link
Contributor

@mgreter mgreter commented Aug 15, 2014

In reference to: madskristensen/WebEssentials2013#1406

Libsass currently cannot handle unicode file paths. Although this is not really the fault of libsass. There is no way to access unicode paths that have codepoints not available in the current codepage, as the ANSI functions will only work with the current codepage [*].

One way to solve this would be to replace all ANSI IO functions with the windows specific ones (like CreateFileW etc). Since libsass only reads data from the filesystem, we can use shortnames to access files with ANSI functions. This Patch does exactly that.

This patch will need the windows headers if _WIN32 is defined. I guess it should compile safe with different compilers on windows. Although I just tested it with gcc version 4.6.3 (gcc-4.6.3 release with patches [build 20121012 by perlmingw.sf.net]).

Use shortnames for all ANSI file operations
Finding the correct code-point and increasing plus one is
the correct way, although it also works by just "skipping"
the first code point byte (which is what c_index + 1 does).
Remove the hassle to write and maintain code to handle
Unicode. Use this light-weight (header-only) library to
handle all Unicode related stuff. Can handle invalid
Unicode strings correctly and more gracefully.

http://utfcpp.sourceforge.net/
The names were (IMO) not very intuitive.
I tried to apply some meaningful conventions.
@mgreter
Copy link
Contributor Author

mgreter commented Aug 15, 2014

Took the liberty to replace the native utf8 code with a well known unicode implementation. Added try/catch blocks for unicode errors in internal sass functions. Renamed some utf8 helpers to a more consistent naming (IMHO).

http://www.codeproject.com/Articles/14637/UTF-With-C-in-a-Portable-Way

@mgreter
Copy link
Contributor Author

mgreter commented Aug 16, 2014

Sorry for the mess! Figured using the native windows functions are safer to use as shortnames may not be available in the future. This is also the only way if libsass should ever need to write files with unicode paths IMO.

Shortnames may become obsolete or can be disabled.
This implementation should be more future proof!
Calling error in catch will throw, but clang doesn't know!
@am11
Copy link
Contributor

am11 commented Aug 23, 2014

👍

@am11
Copy link
Contributor

am11 commented Aug 24, 2014

@akhleung, would you please review and merge it soon, since node-sass is progressing towards a next release. It would be immaculate timing if this PR makes its way to the upcoming version of node-sass. 😄

Thanks!

@mgreter
Copy link
Contributor Author

mgreter commented Sep 3, 2014

Added a commit to update sass2scss to the latest tagged version (0.9.1).

Forgotten to close the handle in windows implementation.
HamptonMakes added a commit that referenced this pull request Oct 2, 2014
Fixes unicode filepath handling on windows
@HamptonMakes HamptonMakes merged commit 65ffcf7 into sass:master Oct 2, 2014
@mgreter mgreter deleted the windows_unicode_paths branch October 5, 2014 20:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants