Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Skip conversion if charset is the same #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pupaxxo
Copy link

@pupaxxo pupaxxo commented Dec 20, 2019

No description provided.

@zbateson
Copy link
Owner

Hi @pupaxxo -- wouldn't that be better a few lines down after the calls to getMbCharset to normalize them?

For instance the target could be "utf-8" and the source "UTF8" according to content-type, so calling that a few lines down may catch more occurrences of what you're trying to prevent... although would involve looking up charsets, etc...

@pupaxxo
Copy link
Author

pupaxxo commented Dec 28, 2019

Yes, you are right. It surely better to normalize them before checking the two charset. I'll update the branch

@pupaxxo
Copy link
Author

pupaxxo commented Dec 28, 2019

I'm using the web ui, can you squash the two commits? Thanks.

@zbateson
Copy link
Owner

zbateson commented Jan 2, 2020

Aah, sorry it wasn't that simple either. This now fails a test. It's because getMbCharset can return false if the charset is not supported by mb_* (not listed in mb_list_encodings). That would make the conditional more complicated if you wanted to check against iconv charsets as well.

To be honest, not sure it's worth it either -- in the end the mb_* call and iconv call probably just return the string in the same way if the source/target are the same, no?

The other option would be to: write a more complicated conditional, or: incorporate the checks into the existing conditions, and write an additional condition for the iconv call, or: go back to the first commit, but use getNormalizedCharset to compare the two. That would result in multiple calls to getNormalizedCharset though because it's called in getMbCharset/getIconvCharset, and so could likely negate any benefit from not calling mb_convert*/iconv.

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

Successfully merging this pull request may close these issues.

2 participants