-
Notifications
You must be signed in to change notification settings - Fork 472
Fixes unicode filepath handling on windows #471
Conversation
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.
|
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 |
|
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!
|
👍 |
|
@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! |
|
Added a commit to update
|
Forgotten to close the handle in windows implementation.
Fixes unicode filepath handling on windows
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
shortnamesto access files with ANSI functions. This Patch does exactly that.This patch will need the windows headers if
_WIN32is 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]).