Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Why is utf-8 a special case #12

Open
kierans opened this issue Jun 29, 2019 · 2 comments
Open

Why is utf-8 a special case #12

kierans opened this issue Jun 29, 2019 · 2 comments
Labels

Comments

@kierans
Copy link

kierans commented Jun 29, 2019

If the charset is "utf-8" "utf8" is returned. If the charset is anything else (eg: "utf-16") it is returned with a dash.

Having inconsistent formatting of results is not helpful as it's hard what to know what to test against. For example, I'm writing chaijs/chai-http#253 and now have to "despecial" utf8

In my opinion the charset should just be returned.

@fengmk2
Copy link
Member

fengmk2 commented Jun 29, 2019

I don't remember why I force to change utf-8 to utf8, but I think they are same in Node.js.
Maybe I was following the fs module default encoding format is utf8. https://npm.taobao.org/mirrors/node/latest/docs/api/fs.html#fs_fs_readfile_path_options_callback

@kierans
Copy link
Author

kierans commented Jun 29, 2019

Thanks @fengmk2. It's annoying that node specifies encoding different to HTTP. However in HTTP, charsets have dashes https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

So you either need to convert all UTF response to non dash (ie: "utf8, utf16, etc), or return the dashed version that is in the HTTP response and let the caller do the matching.

It's the inconsistency that's the real problem.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants