Skip to content

fix(audio-track): match assocLang using its own guard, not lang's - #8028

Merged
robwalch merged 2 commits into
video-dev:masterfrom
winklemad:fix/assoclang-match-guard
Sep 8, 2026
Merged

robwalch merged 2 commits into
video-dev:masterfrom
winklemad:fix/assoclang-match-guard

Conversation

@winklemad

Copy link
Copy Markdown
Contributor

Summary

In matchesOption (src/utils/rendition-helper.ts), the ASSOC-LANGUAGE clause is gated on the wrong variable:

(lang === undefined || languagesMatch(lang, track.lang)) &&
(lang === undefined || track.assocLang === assocLang) &&   // <- uses lang's guard

Every other clause follows X === undefined || track.X === X, but this one checks assocLang while gating on lang. Two consequences:

  1. An option that requests a specific assocLang but doesn't constrain lang matches tracks with a different assocLang (the clause short-circuits to true because lang === undefined).
  2. An option that constrains lang but not assocLang fails to match a track that carries an assocLang (because it then requires track.assocLang === undefined).

Fix

Gate the clause on assocLang === undefined, like every sibling clause.

Test

Added tests/unit/utils/rendition-helper.ts covering both directions. On master the "different assocLang" case wrongly matches and the "lang-only" case wrongly fails to match; both pass with this change.

matchesOption gated the ASSOC-LANGUAGE clause on `lang === undefined` instead
of `assocLang === undefined`, so an option that requested a specific assocLang
matched tracks with a different one (when it did not also constrain lang), and
an option that constrained lang but not assocLang failed to match a track that
carried an assocLang. Use assocLang's own guard, like every other clause.
Comment thread tests/unit/utils/rendition-helper.ts Outdated
type: 'AUDIO',
url: '',
...overrides,
} as MediaPlaylist;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build the track through a typed const instead of asserting the object
literal, which is what @typescript-eslint/consistent-type-assertions
wants and matches how audio-track-controller builds its tracks.

The test file was also missing from tests/index.js, so it never ran.
@winklemad

Copy link
Copy Markdown
Contributor Author

Fixed in 830176f. Built the track through a typed const instead of asserting the object literal, matching how audio-track-controller sets its tracks up.

While checking that, I noticed the test file was never added to tests/index.js, so it wasn't running at all. Added it there too. Local run is 1199 tests, and I confirmed the new one fails on the old guard and passes with the fix.

@robwalch
robwalch merged commit 57fb51e into video-dev:master Sep 8, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from Top priorities to Done in HLS.js Release Planning and Backlog Sep 8, 2026
@winklemad

Copy link
Copy Markdown
Contributor Author

Thanks @robwalch — appreciate the review.

akashchamp pushed a commit to akashchamp/hls.js that referenced this pull request Sep 25, 2026
…deo-dev#8028)

* fix(audio-track): match assocLang using its own guard, not lang's

matchesOption gated the ASSOC-LANGUAGE clause on `lang === undefined` instead
of `assocLang === undefined`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants