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

🐛 URLs (external links) require additional urldecoding #566

Open
1 task done
ToshY opened this issue Nov 15, 2024 · 0 comments
Open
1 task done

🐛 URLs (external links) require additional urldecoding #566

ToshY opened this issue Nov 15, 2024 · 0 comments
Labels

Comments

@ToshY
Copy link
Contributor

ToshY commented Nov 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

URLs, in this case "Resources" (also referred as "External links") can contain links to sites that have japanese characters in the URL path.

Example: https://api.jikan.moe/v4/anime/21/full

Results for external are the following:

Expected Behavior

Steps To Reproduce

https://api.jikan.moe/v4/anime/21/full

Environment

jikan-me/jikan: 5.0.0-dev

Anything else?

Workaround

Manually urldecode the URLs that jikan returns.


Edit

For some, this would also require mb_encoding_check, as apparently some URLs use Shift JIS (and possible other encodings). If not converted with mb_convert_encoding, this can cause errors like General error: 1366 Incorrect string value when inserting into a SQL database.

https://api.jikan.moe/v4/anime/28353/full

snippet

    public function urlDecodeWithMbConvertEncoding(?string $url): string
    {
        $decodedString = urldecode($url);
        foreach (['UTF-8', 'SJIS', 'ISO-8859-1', 'Windows-1252'] as $encoding) {
            if (mb_check_encoding($decodedString, $encoding) === false) {
                continue;
            }

            return mb_convert_encoding($decodedString, 'UTF-8', $encoding);
        }

        return $decodedString;
    }
@ToshY ToshY added the bug label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant