windows-registry-node icon indicating copy to clipboard operation
windows-registry-node copied to clipboard

Solves #44 wrong encoding

Open Jakovb opened this issue 6 years ago • 5 comments

Solves #44 !

Jakovb avatar Jun 07 '18 07:06 Jakovb

I don't think this is the correct fix. The problem is that we're using RegQueryValueExA which returns strings in the current Windows code page and then we're treating that as if it's UTF-8 text. Which means that as it stands we can only correctly read ASCII (code points 0-127); this change means we now support 128-255 where the Windows code page matches code points 128-255 of Unicode, which is more or less Latin-1, but it's not a complete fix.

I think instead the fix is to use the -W functions throughout, i.e. RegQueryValueExW here, which use UTF-16 strings which can represent all Unicode code points, and use Node's Buffers to encode and decode strings in utf16le. I have spent a little time looking at this but have run into some issues getting the tests working (registry permissions on Windows 10, reg delete doesn't work?). I'll push my work-in-progress to a branch when I get a chance.

In any case please squash these five commits down to a single commit so that it's obvious you're only actually changing the one line!

RupW avatar Jun 15 '18 09:06 RupW

I've been playing with ExW myself and that was my original idea. And alike you was getting a plenty of side effect issues. Which made me just rewrite this and adding binary there does the trick. Please do try with my solution and report on results.

Will squash-apologizes for that.

Jakovb avatar Jun 15 '18 09:06 Jakovb

I'm not sure my issues were side effects of my change though: the unit tests don't work for me either on master or on your branch. I can't test right now but I'd guess your version won't work with e.g. curly quotes, i.e. “”, since they're characters >255.

FWIW here's my branch but I'm not sure when I'll get time to work on this more: https://github.com/RupW/windows-registry-node/commits/issue-44 The last two commits are relevant.

RupW avatar Jun 15 '18 09:06 RupW

I have fixed up my RegQueryValueExW commit: https://github.com/RupW/windows-registry-node/commit/3fdbae5bf26b572bcd2c2d513e2e8f15ccd66ace

and it will successfully read value 'test_value £ “” ä/ü/ö' from the registry. This version won't return the curly quotes for me (but does return the £ and accented characters which the current master doesn't).

RupW avatar Jun 15 '18 10:06 RupW

For the record the changes mentioned above are part of #60

zbynek avatar May 16 '19 12:05 zbynek