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
external_files: detect locales with a region like en-US #13916
Conversation
Download the artifacts for this pull request: |
So what about |
I guess we should just allow any length? |
According to the BCP 47 language tags standard, there will only be 2 or 3 characters before the first |
player/external_files.c
Outdated
i--; | ||
} | ||
|
||
if (n < 2 || i == 0 || name.start[i] != thing) | ||
if (lang_length < 2 || lang_length > 6 || (name.start[i] != '-' && lang_length > 3)) | ||
return (struct bstr){NULL, 0}; |
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.
return (struct bstr){NULL, 0}; | |
return (struct bstr){0}; |
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.
Done.
The current detection is too lenient, it defaults to loading subtitles that do not comply with the specifications, such as test-en and en-simpletest-simpletest. As I mentioned earlier: according to the BCP 47 language tags standard, there will only be 2 or 3 characters before the first And according to the BCP 47 language tags standard, there will be a maximum of eight characters after each hyphens (-). Therefore, we still need to check the eight character limit after each hyphens (-). Refer to relevant BCP 47 language tags normative content: |
8cd0cf7
to
edc0ed9
Compare
This loads subtitle files like foo.en-US.srt with --sub-auto=exact. To preserve the case of these locales and not convert them to e.g. en-us, stop lower casing filenames, and instead use case insensitive functions to check if the media filename is contained in the external filenames. Extensions, whitelisted cover art filenames and idx files were already being compared case insensitively. Fixes mpv-player#12372, fixes mpv-player#13251.
bb96c49
to
c5812e6
Compare
commit 1: external_files: rename variables in guess_lang_from_filename()
commit 2: external_files: detect locales with a region like en-US
This loads subtitle files like foo.en-US.srt with --sub-auto=exact.
To preserve the case of these locales and not convert them to e.g. en-us, stop lower casing filenames, and instead use case insensitive functions to check if the media filename is contained in the external filenames. Extensions, whitelisted cover art filenames and idx files were already being compared case insensitively.
Fixes #12372, fixes #13251.