Describe the bug
When a webpage has an "og:video" meta tag, but it doesn't have any "og:video:type" or "og:video:secure_url" meta tags, the library crashes with a "Error: link-preview-js could not fetch link information TypeError: Cannot read property '0' of null".
By browsing the code, I found that in the getVideos function, the nodeTypes and nodeSecureUrls variables can be null. Later, in the same function, there's a loop that goes over the video tags and unsafely accesses the corresponding index of nodeTypes and nodeSecureUrls, crashing in this particular case.
Expected behavior
Not crashing. Either the metaTag function returns an empty array when no tags found, or access the nodeTypes inside the loop in the getVideos function in a safer way, e.g:
nodeType = nodeTypes ? nodeTypes[index] : ''; and nodeSecureUrl = nodeSecureUrls ? nodeSecureUrls[index] : '';
Describe the bug When a webpage has an "og:video" meta tag, but it doesn't have any "og:video:type" or "og:video:secure_url" meta tags, the library crashes with a "Error: link-preview-js could not fetch link information TypeError: Cannot read property '0' of null".
By browsing the code, I found that in the getVideos function, the nodeTypes and nodeSecureUrls variables can be null. Later, in the same function, there's a loop that goes over the video tags and unsafely accesses the corresponding index of nodeTypes and nodeSecureUrls, crashing in this particular case.
To Reproduce Steps to reproduce the behavior:
Expected behavior Not crashing. Either the metaTag function returns an empty array when no tags found, or access the nodeTypes inside the loop in the getVideos function in a safer way, e.g:
nodeType = nodeTypes ? nodeTypes[index] : '';
andnodeSecureUrl = nodeSecureUrls ? nodeSecureUrls[index] : '';
Additional context Here's the getVideos function: https://github.com/ospfranco/link-preview-js/blob/3ef3f895cd003af2046a84241db58f1cbf665939/index.ts#L132
Here are the lines that crash: https://github.com/ospfranco/link-preview-js/blob/3ef3f895cd003af2046a84241db58f1cbf665939/index.ts#L167 https://github.com/ospfranco/link-preview-js/blob/3ef3f895cd003af2046a84241db58f1cbf665939/index.ts#L172
Thank you for your work! 😀