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

Introduce IANA-BCP47 to validate the IETF language code #54

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

Conversation

Masterain98
Copy link
Contributor

@Masterain98 Masterain98 commented Dec 10, 2024

Hello again,

This PR introduces a more robust solution for validating user input of IETF language codes using the iana-bcp47 library. Compared to the older bcp47 library, this new implementation validates each subtag against the IANA Language Subtag Registry, rather than relying on a predefined whitelist.

Context

highfestiva/bcp47.py#7

In my experience with an older version of pymkv, valid language codes such as zh-Hans-CN would cause a ValueError during validation. These codes are valid according to BCP47 standards but were not included in the whitelist used by bcp47. To address this issue, I decided to implement a validator that strictly adheres to IANA's rules, which this PR introduces.

What's Changed

Previously, the is_bcp47 function was removed, and user input was directly set as the language metadata. While I have not tested whether incorrect language codes can cause issues when MKV files are loaded in other software, I believe a simple validation mechanism should still be included.

With the proposed logic, if the user-entered language code fails validation:

  • A warning message is displayed with specific details about the error.
  • The language of the MKVTrack is set to None if the code is invalid.

This ensures that language metadata conforms to IANA standards while providing helpful feedback to users.

source of iana-bcp47: https://github.com/Masterain98/iana-bcp47

Introduce IANA-BCP47 to validate IETF language code
remove `pytest.deprecated_call`
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 66.98%. Comparing base (b3e1883) to head (ea22f79).

Files with missing lines Patch % Lines
pymkv/MKVTrack.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #54      +/-   ##
==========================================
+ Coverage   66.87%   66.98%   +0.10%     
==========================================
  Files          10       10              
  Lines         948      954       +6     
==========================================
+ Hits          634      639       +5     
- Misses        314      315       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GitBib
Copy link
Owner

GitBib commented Dec 16, 2024

The iana-bcp47 library doesn’t appear fully vetted yet, and it’s lacking solid tests. I need some time to review it, and after that, I’ll decide whether to include iana-bcp47 as a dependency.

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