Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit acc5b60

Browse files
cschanajChan Chak Shing
andauthored
Show the grey icon for whitelisted sites with a port number (#19294)
* Update background.js * Update getNormalisedHostname to handle port numbers Co-authored-by: Chan Chak Shing <[email protected]>
1 parent 0242bd1 commit acc5b60

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

chromium/background-scripts/background.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ function updateState () {
188188
return;
189189
}
190190

191+
// tabUrl.host instead of hostname should be used to show the "disabled" status properly (#19293)
191192
const tabUrl = new URL(tabs[0].url);
192-
const hostname = util.getNormalisedHostname(tabUrl.hostname);
193+
const host = util.getNormalisedHostname(tabUrl.host);
193194

194-
if (isExtensionDisabledOnSite(hostname) || iconState == "disabled") {
195+
if (isExtensionDisabledOnSite(host) || iconState == "disabled") {
195196
if ('setIcon' in chrome.browserAction) {
196197
chrome.browserAction.setIcon({
197198
path: {

chromium/background-scripts/util.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ function loadExtensionFile(url, returnType) {
6262

6363
/**
6464
* Remove tailing dots from hostname, e.g. "www.example.com."
65+
* Preserve port numbers if they are used
6566
*/
66-
function getNormalisedHostname(hostname) {
67+
function getNormalisedHostname(host) {
68+
let [ hostname, port ] = host.split(":");
6769
while (hostname && hostname[hostname.length - 1] === '.' && hostname !== '.') {
6870
hostname = hostname.slice(0, -1);
6971
}
72+
if (port) {
73+
return `${hostname}:${port}`;
74+
}
7075
return hostname;
7176
}
7277

chromium/test/util_test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ describe('util.js', function() {
4949
});
5050

5151
describe('getNormalisedHostname', function() {
52-
it('removes tailing dots', function() {
52+
it('preserve port numbers', function() {
53+
assert.strictEqual(util.getNormalisedHostname('example.com'), 'example.com');
54+
assert.strictEqual(util.getNormalisedHostname('example.com:8080'), 'example.com:8080');
55+
});
56+
57+
it('removes tailing dots and preserve port numbers', function() {
5358
assert.strictEqual(util.getNormalisedHostname('example.com.'), 'example.com');
59+
assert.strictEqual(util.getNormalisedHostname('example.com.:8080'), 'example.com:8080');
5460
assert.strictEqual(util.getNormalisedHostname('example.com..'), 'example.com');
61+
assert.strictEqual(util.getNormalisedHostname('example.com..:8080'), 'example.com:8080');
5562
});
5663

5764
it('preserves a single dot', function() {

0 commit comments

Comments
 (0)