fix(metadata): guard getAvailableFunctions against invalid locale codes (HF-249)#1710
Merged
sequba merged 1 commit intoJul 14, 2026
Conversation
…es (HF-249) registerLanguage does not validate the shape of a language code, so a caller can register a structurally invalid one (e.g. underscore-style 'pt_BR'). The function-list collator did new Intl.Collator(toBcp47Locale(code)) directly, and Intl.Collator throws a RangeError on a structurally invalid tag (it does not fall back to the default locale), so getAvailableFunctions (static and instance) crashed for such a code. Wrap collator construction in a createLocaleCollator helper that falls back to the default collator on RangeError, and correct the toBcp47Locale JSDoc which wrongly claimed unrecognized tags fall back to the default locale. Co-authored-by: Kuba Sekowski <sequba@users.noreply.github.com>
Contributor
|
Task linked: HF-249 HF function documentation available via API |
Performance comparison of head (368bc15) vs base (18d4246) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/hf-249-function-metadata-api #1710 +/- ##
========================================================================
+ Coverage 96.42% 96.59% +0.16%
========================================================================
Files 192 192
Lines 15585 15589 +4
Branches 3447 3447
========================================================================
+ Hits 15028 15058 +30
+ Misses 557 531 -26
🚀 New features to boost your workflow:
|
2d9196e
into
feature/hf-249-function-metadata-api
28 of 29 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Addresses a code-review finding on #1692:
getAvailableFunctionscan throw aRangeErrorfor a caller-registered, malformed language code.buildAvailableFunctionsbuilt its sort collator withnew Intl.Collator(toBcp47Locale(code)).toBcp47Localeonly hyphenates the canonical<ll><RR>shape and passes any other string through unchanged, andregisterLanguageperforms no shape validation on the code.Intl.Collatorthrows aRangeErroron a structurally invalid language tag (it does not silently fall back to the default locale). So a caller who registers an underscore-style code such as'pt_BR'(or'en_US','x','12') and then callsgetAvailableFunctions(static or instance) crashes.Built-in language codes are all safe, so this only affects consumer-registered malformed codes → important, not critical.
The
toBcp47LocaleJSDoc was also wrong: it claimed unrecognized tags "fall back to the default locale," whichIntl.Collatordoes not do for invalid tags.Fix
createLocaleCollator(languageCode)which wraps theIntl.Collatorconstruction in atry/catchand falls back to the environment-default collator (new Intl.Collator()) onRangeError, so listing functions never crashes on a non-BCP-47 code.buildAvailableFunctions.toBcp47LocaleJSDoc to describe the real behavior (invalid tags throw; the throw is handled bycreateLocaleCollator).getFunctionDetailsis unaffected — it does not sort and never constructs a collator.How did you test your changes?
'pt_BR'then callinggetAvailableFunctions('pt_BR')threwRangeError: Incorrect locale information provided.'pt_BR','en_US','x', and'12'each return the full, alphabetically-sorted 419-entry list; well-formed'enGB'is unchanged.new Intl.Collator('pt_BR'|'en_US'|'x'|'12')throw while'zz-ZZ'/'qqq'do not.tsc --noEmitclean;eslint src/HyperFormula.ts0 errors;test/smoke.spec.ts4/4.Types of changes
Related issues:
Notes for reviewers
registerLanguage) would be a broader, potentially breaking change, so it's intentionally out of scope here.hyperformula-tests): register a'pt_BR'-style code and assertgetAvailableFunctionsreturns a sorted list instead of throwing.