Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484 #13675

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const settings = require('../../../js/constants/settings')
// Utils
const getSetting = require('../../../js/settings').getSetting
const {makeImmutable, isMap} = require('../../common/state/immutableUtil')
const urlParse = require('../../common/urlParse')
const getBaseDomain = require('../../../js/lib/baseDomain').getBaseDomain

const validateState = function (state) {
state = makeImmutable(state)
Expand Down Expand Up @@ -65,12 +67,28 @@ const ledgerState = {
return state.setIn(['ledger', 'locations', url, prop], value)
},

getVerifiedPublisherLocation: (state, url) => {
state = validateState(state)
if (url == null) {
return null
}

let publisherKey = state.getIn(['ledger', 'locations', url, 'publisher'])

if (!publisherKey) {
const parsedUrl = urlParse(url) || {}
if (parsedUrl.hostname != null) {
publisherKey = getBaseDomain(parsedUrl.hostname)
}
}
return publisherKey
},

getLocationProp: (state, url, prop) => {
state = validateState(state)
if (url == null || prop == null) {
return null
}

return state.getIn(['ledger', 'locations', url, prop])
},

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/navigation/publisherToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PublisherToggle extends React.Component {
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
const location = activeFrame.get('location', '')
const locationId = getBaseUrl(location)
const publisherKey = ledgerState.getLocationProp(state, locationId, 'publisher')
const publisherKey = ledgerState.getVerifiedPublisherLocation(state, locationId)

const props = {}
// used in renderer
Expand Down
46 changes: 22 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions test/unit/app/common/state/ledgerStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,71 @@ describe('ledgerState unit test', function () {
assert.equal(result, 'corrupted')
})
})

describe('getVerifiedPublisherLocation', function () {
it('null case', function () {
const result = ledgerState.getVerifiedPublisherLocation(defaultState)
assert.equal(result, null)
})
it('empty string', function () {
const url = ''
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, null)
})
it('url shortener', function () {
const url = 'https://www.duckduckgo.com'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'duckduckgo.com')
})
it('url shortner with sub levels', function () {
const url = 'https://brianbondywww.com/projects/'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'brianbondywww.com')
})
it('url shortner with sub levels', function () {
const url = 'https://www.brianbondywww.com/projects/'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'brianbondywww.com')
})
it('url shortner with sub levels', function () {
const url = 'https://www2.brianbondy.com/projects/'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'brianbondy.com')
})
it('url shortner with sub levels', function () {
const url = 'https://subdomain.brianbondy.com/projects/'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'brianbondy.com')
})
it('url shortener with multi sublevels', function () {
const url = 'https://www.coindesk.com/market-center/ethereum'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'coindesk.com')
})
it('url shortener with any protocol', function () {
const url = 'anything://www.this.any.site.com'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'site.com')
})
it('url shortener with any protocol [ccTLD]', function () {
const url = 'anything://www.this.any.site.co.jp'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'site.co.jp')
})
it('url shortener with any protocol with sublevels', function () {
const url = 'anything://www.this.any.site.co.jp/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'site.co.jp')
})
it('url shortener with any protocol with sublevels ultra log', function () {
const url = 'anything://www.this.any.site.co.jp/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/.com/r/s/t/u/v'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'site.co.jp')
})
it('url shortener with any protocol confusion', function () {
const url = 'anything://www.2.www.ww.www.this.any.site.com.org.com'
const result = ledgerState.getVerifiedPublisherLocation(defaultState, url)
assert.equal(result, 'org.com')
})
})
})