Skip to content

Fix bugs in loader parsers#1341

Merged
obiot merged 1 commit intomasterfrom
fix/loader-parser-bugs
Mar 31, 2026
Merged

Fix bugs in loader parsers#1341
obiot merged 1 commit intomasterfrom
fix/loader-parser-bugs

Conversation

@obiot
Copy link
Copy Markdown
Member

@obiot obiot commented Mar 31, 2026

Summary

  • script.js: Fix undefined crossOrigin variable reference — was checking an undeclared variable instead of settings.crossOrigin
  • video.js: Fix unsafe regex match on data URLs (null check), fix missing error parameter in videoElement.onerror callback, normalize import path
  • fontface.js: Fix missing error parameter in font.load() rejection handler, fix JSDoc example syntax

Test plan

  • All 1921 tests pass
  • New tests: onerror callbacks for invalid image/JSON/binary sources
  • New test: inline TMX data returns correct resource count

🤖 Generated with Claude Code

script.js:
- Fix undefined `crossOrigin` variable reference (should be `settings.crossOrigin`)

video.js:
- Fix unsafe regex match on data URLs (null check before array access)
- Fix missing error parameter in videoElement.onerror callback
- Normalize import path (./../../ → ../../)

fontface.js:
- Fix missing error parameter in font.load() rejection handler
- Fix incomplete JSDoc example (missing opening bracket)

Tests:
- Add onerror tests for invalid image, JSON, and binary sources
- Add inline TMX data return value test (covers tmx.js fix from prior commit)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 31, 2026 05:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes several correctness issues in the asset loader parser implementations, improving error propagation and handling of edge cases (notably data URLs), and adds regression tests to ensure loader error callbacks fire reliably.

Changes:

  • Fix script parser CORS handling by using settings.crossOrigin (instead of an undeclared variable).
  • Harden video parser data URL MIME parsing (null-safe) and pass the event/error argument through videoElement.onerror.
  • Fix fontface parser rejection handler to forward the rejection error and correct a broken JSDoc example.
  • Add loader tests covering onerror behavior for invalid sources and inline TMX resource counting.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/melonjs/tests/loader.spec.js Adds regression tests for onerror callbacks (image/json/binary) and inline TMX load() return count.
packages/melonjs/src/loader/parsers/video.js Normalizes import path, avoids unsafe regex match access for data URLs, and forwards the onerror argument.
packages/melonjs/src/loader/parsers/script.js Correctly applies crossOrigin from loader-provided settings.
packages/melonjs/src/loader/parsers/fontface.js Forwards the actual font loading rejection error to onerror and fixes invalid JSDoc example syntax.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@obiot obiot merged commit a829024 into master Mar 31, 2026
10 checks passed
@obiot obiot deleted the fix/loader-parser-bugs branch March 31, 2026 07:16
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