Skip to content

Prevent DEFAULTOPTIONS mutation and validate max-width/height inputs #13

@shekhei

Description

@shekhei

Context

src/index.js uses Object.assign(DEFAULTOPTIONS, loaderUtils.getOptions(this)), which mutates the shared DEFAULTOPTIONS object across loader invocations. It also parses width/height with parseInt() without validation, which can yield NaN and still calls gm.resize().

Why this matters

Shared mutation can leak configuration between builds/runs, and invalid options can lead to confusing failures or unexpected output sizes.

Proposal

  • Avoid mutating defaults by cloning options.
  • Validate numeric width/height and provide clear errors or fallbacks.
  • Use an explicit radix in parseInt or Number() with Number.isFinite checks.

Tasks

  • Change option merge to Object.assign({}, DEFAULTOPTIONS, loaderOptions) (or spread).
  • Validate max-width / max-height and handle invalid values (error or skip resize).
  • Add tests to cover invalid or missing values and ensure defaults do not leak between runs.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions