Skip to content

Commit

Permalink
Fixes verfied check for YouTube
Browse files Browse the repository at this point in the history
Resolves brave#14351

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Jun 21, 2018
1 parent 6527d81 commit bbee6f1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/extensions/brave/content/scripts/metaScraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,16 @@ const metaScraperRules = {
requestHandlerApi.strict(wrap(html => requestHandlerApi.getValue(html.querySelectorAll('[class*="author"]')))),
requestHandlerApi.strict(wrap(html => requestHandlerApi.getValue(html.querySelectorAll('[class*="byline"]'))))
]
},

getUrlRules: () => {
const wrap = rule => ({htmlDom, url}) => {
const value = rule(htmlDom)
return requestHandlerApi.isUrl(value, {relative: false}) && value
}

return [
wrap(html => requestHandlerApi.getHref(html.querySelector('link[rel="canonical"]')))
]
}
}
14 changes: 12 additions & 2 deletions app/extensions/brave/content/scripts/requestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ const requestHandlerApi = {
const result = {
image: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getImageRules() }),
title: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getTitleRules() }),
author: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getAuthorRules() })
author: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getAuthorRules() }),
url: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getUrlRules() })
}

ipc.send(`got-publisher-info-${url}`, {
error: null,
body: {
url: finalUrl,
finalUrl: finalUrl,
url: sanitizeHtml(result.url) || finalUrl,
title: sanitizeHtml(result.title) || '',
image: sanitizeHtml(result.image) || '',
author: sanitizeHtml(result.author) || ''
Expand Down Expand Up @@ -116,6 +118,14 @@ const requestHandlerApi = {
return selector.src
},

getHref: (selector) => {
if (!selector) {
return null
}

return selector.href
},

urlTest: (url, opts) => {
let relative
if (opts == null) {
Expand Down
58 changes: 58 additions & 0 deletions diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
diff --git a/app/extensions/brave/content/scripts/metaScraper.js b/app/extensions/brave/content/scripts/metaScraper.js
index e8855b2ff..5dc2316d2 100644
--- a/app/extensions/brave/content/scripts/metaScraper.js
+++ b/app/extensions/brave/content/scripts/metaScraper.js
@@ -98,5 +98,16 @@ const metaScraperRules = {
requestHandlerApi.strict(wrap(html => requestHandlerApi.getValue(html.querySelectorAll('[class*="author"]')))),
requestHandlerApi.strict(wrap(html => requestHandlerApi.getValue(html.querySelectorAll('[class*="byline"]'))))
]
+ },
+
+ getUrlRules: () => {
+ const wrap = rule => ({htmlDom, url}) => {
+ const value = rule(htmlDom)
+ return requestHandlerApi.isUrl(value, {relative: false}) && value
+ }
+
+ return [
+ wrap(html => requestHandlerApi.getHref(html.querySelector('link[rel="canonical"]')))
+ ]
}
}
diff --git a/app/extensions/brave/content/scripts/requestHandler.js b/app/extensions/brave/content/scripts/requestHandler.js
index 7cf875893..518680c77 100644
--- a/app/extensions/brave/content/scripts/requestHandler.js
+++ b/app/extensions/brave/content/scripts/requestHandler.js
@@ -51,13 +51,15 @@ const requestHandlerApi = {
const result = {
image: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getImageRules() }),
title: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getTitleRules() }),
- author: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getAuthorRules() })
+ author: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getAuthorRules() }),
+ url: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getUrlRules() })
}

ipc.send(`got-publisher-info-${url}`, {
error: null,
body: {
- url: finalUrl,
+ finalUrl: finalUrl,
+ url: sanitizeHtml(result.url) || finalUrl,
title: sanitizeHtml(result.title) || '',
image: sanitizeHtml(result.image) || '',
author: sanitizeHtml(result.author) || ''
@@ -116,6 +118,14 @@ const requestHandlerApi = {
return selector.src
},

+ getHref: (selector) => {
+ if (!selector) {
+ return null
+ }
+
+ return selector.href
+ },
+
urlTest: (url, opts) => {
let relative
if (opts == null) {

0 comments on commit bbee6f1

Please sign in to comment.