Skip to content

Commit

Permalink
fix(audio): don't consider iframe referencing itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 17, 2023
1 parent 4409000 commit 815534a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/metascraper-audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ module.exports = ({ getIframe = _getIframe } = {}) => {
const srcs = []

iframe.each(function () {
const src = $(this).attr('src')
const normalizedUrl = normalizeUrl(url, src)
const iframeUrl = normalizeUrl(url, $(this).attr('src'))
if (
typeof normalizedUrl === 'string' &&
normalizedUrl.startsWith('http') &&
srcs.indexOf(normalizedUrl) === -1
typeof iframeUrl === 'string' &&
iframeUrl !== url &&
srcs.indexOf(iframeUrl) === -1
) {
srcs.push(normalizedUrl)
srcs.push(iframeUrl)
}
})

Expand Down
7 changes: 7 additions & 0 deletions packages/metascraper-helpers/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ test('.normalizeUrl', t => {
)
t.is(normalizeUrl('https://example.com/'), 'https://example.com/')
t.is(normalizeUrl('https://example.com'), 'https://example.com/')

t.is(normalizeUrl('https://www.example.com', 'https://www.example.com/foo'), 'https://www.example.com/foo')
t.is(normalizeUrl('https://www.example.com', '/foo'), 'https://www.example.com/foo')
t.is(normalizeUrl('https://www.example.com', 'file.html'), 'https://www.example.com/file.html')
t.is(normalizeUrl('https://www.example.com', 'data:text/html;base64,PGh0bWw+SGVsbG8sIHdvcmxkITwvaHRtbD4='), 'data:text/html;base64,PGh0bWw+SGVsbG8sIHdvcmxkITwvaHRtbD4=')
t.is(normalizeUrl('https://www.example.com', 'javascript:alert(\'Hello, world!\');'), undefined)
t.is(normalizeUrl('https://www.example.com', 'javascript:void(0)'), undefined)
})

test('.author', t => {
Expand Down

0 comments on commit 815534a

Please sign in to comment.