-
Notifications
You must be signed in to change notification settings - Fork 117
Adds fallback for mb_strlen, fixes #61 #64
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
Conversation
lib/cli/cli.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow WP coding standards here.
Thanks for the feedback @danielbachhuber . I've updated based on your comments. |
lib/cli/cli.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How exactly is using plain substr()
encoding-safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I.e. if it was encoding-safe, people wouldn't have used mb_substr()
in the first place, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Demonstration:
<?php
$str = 'sécurité';
echo substr( $str, 0, 2 ) . "\n";
echo mb_substr( $str, 0, 2, mb_detect_encoding( $str ) ) . "\n";
Output:
s�
sé
@scribu I see your point. Plain Would it be safe to assume UTF-8 encoding in cases where
Outputs:
and could be used as a fallback for |
No, I don't think that's a safe assumption. |
However, I think Edit: Oh, it seems |
What I'd like to have for php-cli-tools is:
For WP-CLI, we can fall back to |
I spoke too soon. We don't use |
Since these functions are just used for displaying data, as opposed to manipulating data that will be sent to a database, I think that's acceptable. The function descriptions are still incorrect, though. |
I'll try to add that clarification in an update of the pull request that also includes @danielbachhuber recommendation for the |
Thanks @jesseoverright. I'd love to get this sorted out in the next couple of days so we can ship |
Sounds good. I'll submit an updated pull request tomorrow.
|
…extensions are missing and encoding is present
Function descriptions are updated. Also added Also included tests for |
Adds fallback for mb_strlen, fixes #61
👍 |
Adds a
function_exists
check formb_strlen()
and will use php'sstrlen()
in place ofmb_strlen()
. Addresses issues with PHP installations that do not have the non-default mbstring extension enabled.