-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Use UTF-8 encoding for std{in,out,err} #11168
Use UTF-8 encoding for std{in,out,err} #11168
Conversation
@metaskills: Could you try this patch on your end? It seems to be working for me :) # stdout.coffee
require("system").stdout.write "ascii 日本語 ✓"
phantom.exit 0 $ ./bin/phantomjs stdout.coffee | hexdump -C
00000000 61 73 63 69 69 20 e6 97 a5 e6 9c ac e8 aa 9e 20 |ascii ......... |
00000010 e2 9c 93 |...|
00000013 |
@execjosh It does work!!! Cant wait till 1.9.1 :) |
FYI, I found out that the built version in master does not "flush" stdout till the process exists. For example:
Where the 1.9 downloaded version does this.
|
I can report that one of these two commits has caused the problem with flushing. So if I revert back to da71c5f and build, I get the expected behavior. |
Hmm... 54f1f60 shouldn't have any functional effects; therefore, the culprit must be e212d7e. Hmm... I'm rebuilding the latest qt in phantomjs right now; so, it'll be a bit before I can build again. Looking at the commit itself, though, it should have been split into two: one to refactor the |
Okay, well, it looks like |
It should work as expected now! |
Thanks for the quick turnaround, @execjosh! 👍 |
I wasn't completely satisfied with the fact that the Also, the Can anyone help fix the qt build to automatically make the codecs? |
I had thought about the same thing. Glad you are addressing it. I could not build this either. I ended up with the following error. Are you saying that I need to do something before or after the build fail to build again?
|
Okay, just as I suspected. The I had to build them manually, like this: $ pushd src/qt/src/plugins/codecs && make && popd The codecs are automagically placed in |
Okay, I think I fixed the text codec build stuff (had to add a step to Can anyone help out and confirm that the linux* and Windows builds didn't get broken, and that the mac build works, too? It'd probably be best to run |
I'm building on an Ubuntu box right now. I don't have the ability to build on Windows, though; so, I hope someone can help out on that front :) |
Looks to me like the build is fine for Ubuntu :) |
I can confirm the build is fine and as expected on OS X. |
It's too big of a change to be backported to 1.9.1. I think it needs to be splitted into two parts: critical fixes for the encoding itself and everything else (including new codes etc). For the latter, please file separate issues so that they can be tracked. |
@ariya: Here's the list of problems and their consequences that I had jumbled into this pull request.
It makes the most sense for the Does that sound like what you had in mind? |
If the wrapped `QFile` was opened with `QIODevice::Unbuffered`, any writes should be unbuffered. However, as currently implemented, using `QTextStream` when the `File` is in "text" mode causes all reads/writes to be buffered. This modification forces a flush in `File::write` if the wrapped `QFile` was opened with `QIODevice::Unbuffered`.
This fixes issue ariya#11162. `File` constructor takes a `QTextCodec *`, codec; but, if codec is `NULL`, then it assumes "binary" mode, which causes non-ASCII characters to be converted to NUL (`\0`) in `File::write`. This change passes the codec for UTF-8 to the `File` constructor for the `std{in,out,err}` instances, thus opening them in *text mode*.
I just can't wait to get these fixes in the wild. I have an open ticket on my mocha-phantomjs project to utilize the stdout features. It will make a lot of our code go away and open doors for things that we could not do before. Thanks to everyone for their hard work! |
@execjosh Thanks for the patch restructuring. I'll give a try! |
You know, looking at #10973, there might need to be a way to set The switch can be a part of implementing #10973, though, I think. Since we don't have anything like node's |
@JamesMGreene: That is definitely the next step for not only the standard streams; but, our filesystem API in general! I had attempted a year ago. However, implementing everything in one blow was a bigger bite than I could chew. I'd like to give it another go :) |
@ariya: Does it work well for you? Synchronizing with the |
Sorry for the delay. Everything looks good so I merged it with minor tweaks (1) 4-space indentation (2) link to the issue in the first commit for a good cross-ref. Thanks! |
Great! Sorry about the indentation problem. By the way, do you prefer the full URL in the commit message, as opposed to just the number? |
I think number is necessary so that it's referenced from the issue. The full URL can be there as a convenience bonus (when checking the log outside GitHub viewer). |
If a `File` is in "text" mode, then it has an encoding. This encoding defaults to UTF-8; however, it can be set only at time of construction (by using `fs.open`). This modification allows the user to change the encoding on-the-fly for "text" mode `File` instances. See #11234 #11234 Spin off from #11168 #11168
Pardon my ignorance if the information is elsewhere, but when will 1.9.1 be released? I've added myself to the mailing list for future updates. |
See [issue 333][1] and pull request #192. **Caveat** `File::read` currently takes no parameters and is equivalent to a "`readAll`". This will be changed later to match [IO/A Spec's `Stream#read`][2]; but, should still be noted. [1]: http://code.google.com/p/phantomjs/issues/detail?id=333 [2]: http://wiki.commonjs.org/wiki/IO/A#Instance_Methods
This fixes issue #11162.
File
constructor takes aQTextCodec *
, codec; but, if codec isNULL
, then it assumes "binary" mode, which causes non-ASCII characters to be converted to NUL (\0
) inFile::write
.This change passes the codec for UTF-8 to the
File
constructor for thestd{in,out,err}
instances, thus opening them in text mode.