laurengarcia / url-metadata

NPM module: Request a url and scrape the metadata from its HTML using Node.js or the browser.
https://www.npmjs.com/package/url-metadata
MIT License
166 stars 44 forks source link

Fixed issue where ensureSecureImageRequest evaluate true when set false. #22

Closed sidshrivastav closed 4 years ago

sidshrivastav commented 4 years ago

Changes implementation by using logical and.

Logical AND (&&)

false && false: false
false && true: false
true && false: false
true && true: true

Logical OR (||)

false || false: false
false || true: true
true || false: true
true || true: true
laurengarcia commented 4 years ago

Fixed in version 2.4.3 just published to npm Sorry for delay.

Since the default for ensureSecureImageRequest is true not false, your solution wouldn't work. Here's what I did instead, it's a bit cleaner than what was there before.

  const opts = Object.assign(
    // defaults
    {
      userAgent: 'MetadataScraper',
      fromEmail: 'example@example.com',
      maxRedirects: 10,
      timeout: 10000,
      descriptionLength: 750,
      ensureSecureImageRequest: true,
      sourceMap: {},
      decode: undefined,
      encode: undefined
    },
    // options passed in override defaults
    options
  )