pqina / filepond-plugin-image-preview

🖼 Show a preview for images dropped on FilePond

Home Page:https://pqina.nl/filepond

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing null ref check

PinkDuck opened this issue · comments

TypeError: s is undefined at DID_UPDATE_ITEM_METADATA@filepond-plugin-image-preview.min.js:9:19658

Where s is an expected crop object, but if there is no crop object the following conditional test fails with null ref.

commented

The issue description lacks detail, please provide a concise test case on codesandbox.io to reproduce and leave a comment, will close till updated.

Within the didUpdateItemMetadata function beginning at line 3142 there is a regex test for crop/markup/resize action change then on line 3169 a use of crop variable without null ref check.

A call to setMetadata("resize") on an FilePond image rendered with preview plugin results in the error above, where object supplied is {"mode":"contain","upscale":false,"size":{"width:732,"height:670}}.

The object returned by file.getMetadata() after image drop (and after upload transform) is:

{
  "resize": {
    "mode": "contain",
    "upscale": false,
    "size": {
      "width": 732,
      "height": 670
    }
  },
  "size": {
    "width": 1478,
    "height": 1108
  },
  "color": null,
  "output": {
    "type": null,
    "quality": null,
    "client": [
      "crop",
      "resize",
      "filter",
      "markup",
      "output"
    ]
  }
}

Evidently no crop property key at the root, so probably a relative referencing issue in the change handler.

commented

Alright, can you try 4.6.9, just published it.

Thanks, that resolved the reported glitch.

However, revealed another of similar type for var aspectRatio = crop.aspectRatio || imageAspectRatio; on line 2663.

Plus a fair batch at 2540 onwards.

commented

Have you registered the crop plugin I wonder?

I haven't done so as I don't have need to make use of cropping and didn't think there was a dependency on it.

I'll try it out to see… ah, fixative impact seen.

Might wish to revise the documentation to mention this (if not wishing to make preview independent of crop).

commented

@PinkDuck okay, glad to hear that fixes it. I will probably fix the plugin later as it should work without the crop plugin.