Skip to content

fix(player): add null safety when accessing srcObj.src and srcObj.type#9193

Open
xxiaoxiong wants to merge 1 commit into
videojs:mainfrom
xxiaoxiong:fix/srcobj-null-check-9185
Open

fix(player): add null safety when accessing srcObj.src and srcObj.type#9193
xxiaoxiong wants to merge 1 commit into
videojs:mainfrom
xxiaoxiong:fix/srcobj-null-check-9185

Conversation

@xxiaoxiong
Copy link
Copy Markdown

Fixes #9185

Description

When srcObj is a non-string object in updateSourceCaches_(), the code accesses srcObj.src and srcObj.type without checking if these properties exist. If srcObj is null, {}, or an object with different keys, src and type will be undefined, leading to silent failures.

Changes

  • src/js/player.js: Add optional chaining (?.) and nullish coalescing (??) for safer access to srcObj.src and srcObj.type.

Fixes videojs#9185

When srcObj is a non-string object, updateSourceCaches_() accesses
srcObj.src and srcObj.type without checking if these properties exist.
If srcObj is null, {}, or an object with different keys, src and type
will be undefined, leading to silent failures.

Add optional chaining and nullish coalescing for safer access.
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.

Bug: updateSourceCaches_() assumes srcObj has src and type properties

1 participant