Commit a1c4fb58 authored by Miguel Alatzar's avatar Miguel Alatzar Committed by Miguel Alatzar
Browse files

Avoid possible reading of property on undefined (#830)

parent 028e7863
......@@ -84,7 +84,12 @@ export const getCurrentTeamUrl = createSelector(
getCurrentTeam,
(state) => getConfig(state).SiteURL,
(currentURL, currentTeam, siteURL) => {
return `${currentURL || siteURL}/${currentTeam.name}`;
const rootURL = `${currentURL || siteURL}`;
if (!currentTeam) {
return rootURL;
}
return `${rootURL}/${currentTeam.name}`;
}
);
......
......@@ -525,4 +525,41 @@ describe('Selectors.Teams', () => {
};
assert.deepEqual(Selectors.getCurrentTeamUrl(withCredentialURLState), credentialURL + '/' + team1.name);
});
it('getCurrentTeamUrl with falsy currentTeam', () => {
const siteURL = 'http://localhost:8065';
const general = {
config: {SiteURL: siteURL},
credentials: {},
};
const falsyCurrentTeamIds = ['', null, undefined];
falsyCurrentTeamIds.forEach((falsyCurrentTeamId) => {
const withSiteURLState = {
...testState,
entities: {
...testState.entities,
teams: {
...testState.entities.teams,
currentTeamId: falsyCurrentTeamId,
},
general,
},
};
withSiteURLState.entities.general = general;
assert.deepEqual(Selectors.getCurrentTeamUrl(withSiteURLState), siteURL);
const credentialURL = 'http://localhost';
const withCredentialURLState = {
...withSiteURLState,
entities: {
...withSiteURLState.entities,
general: {
...withSiteURLState.entities.general,
credentials: {url: credentialURL},
},
},
};
assert.deepEqual(Selectors.getCurrentTeamUrl(withCredentialURLState), credentialURL);
});
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment