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

Commit

Permalink
Merge pull request #11006 from brave/fix/homepage-homograph
Browse files Browse the repository at this point in the history
fix homepage punycode display bypass
  • Loading branch information
bbondy committed Sep 20, 2017
1 parent 2636521 commit a7060a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const UrlUtil = {
parsed.hostname = punycode.toASCII(parsed.hostname)
return urlFormat(parsed)
} catch (e) {
return url
return punycode.toASCII(url)
}
},

Expand Down
11 changes: 11 additions & 0 deletions test/about/preferencesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ describe('General Panel', function () {
.waitForInputText(homepageInput, 'https://www.brave.xn--com-8cd/')
})

it('homepage displays punycode without HTTP prefix', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(prefsUrl)
.waitForVisible(homepageInput)
.click(homepageInput)
.keys(Array.apply(null, Array(50)).map(() => Brave.keys.BACKSPACE))
.keys('а')
.waitForInputText(homepageInput, 'xn--80a')
})

it('homepage can be backspaced', function * () {
yield this.app.client
.tabByIndex(0)
Expand Down
7 changes: 5 additions & 2 deletions test/unit/lib/urlutilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,11 @@ describe('urlutil', function () {
})

describe('getPunycodeUrl', function () {
it('returns empty string if input is not a URL', function () {
assert.equal(UrlUtil.getPunycodeUrl('invalid-url-goes-here'), 'invalid-url-goes-here')
it('returns original string if input is ASCII', function () {
assert.equal(urlUtil.getPunycodeUrl('invalid-url-goes-here'), 'invalid-url-goes-here')
})
it('returns punycode ASCII string if input is non-ASCII', function () {
assert.equal(urlUtil.getPunycodeUrl('ebаy.com'), 'xn--eby-7cd.com')
})
it('returns the punycode URL when given a valid URL', function () {
assert.equal(UrlUtil.getPunycodeUrl('http://brave:brave@ebаy.com:1234/brave#brave'), 'http://brave:brave@xn--eby-7cd.com:1234/brave#brave')
Expand Down

0 comments on commit a7060a1

Please sign in to comment.