import Marionette from 'backbone.marionette';
import Template from './templates/maintenance-main.hbs';
import { getSystemStatus, getMigrationStatus, migrateDatabase } from '../../api/system';
-import { getBaseUrl } from '../../helpers/urls';
+import { getReturnUrl } from '../../helpers/urls';
export default Marionette.ItemView.extend({
template: Template,
loadPreviousPage() {
setInterval(() => {
- window.location = this.options.returnTo || getBaseUrl();
+ window.location.href = getReturnUrl(this.options.returnTo);
}, 2500);
},
import { doLogin } from '../../../store/rootActions';
import { tryGetGlobalNavigation } from '../../../api/nav';
import { IdentityProvider, getIdentityProviders } from '../../../api/users';
-import { getBaseUrl } from '../../../helpers/urls';
+import { getReturnUrl } from '../../../helpers/urls';
interface Props {
doLogin: (login: string, password: string) => Promise<void>;
this.mounted = false;
}
- getReturnUrl = () => {
- const { location } = this.props;
- const queryReturnTo = location.query['return_to'];
- return queryReturnTo ? `${queryReturnTo}${location.hash}` : `${getBaseUrl()}/`;
- };
-
handleSuccessfulLogin = () => {
- window.location.href = this.getReturnUrl();
+ window.location.href = getReturnUrl(
+ this.props.location.query['return_to'],
+ this.props.location.hash
+ );
};
handleSubmit = (login: string, password: string) => {
identityProviders={identityProviders}
onSonarCloud={onSonarCloud}
onSubmit={this.handleSubmit}
- returnTo={this.getReturnUrl()}
+ returnTo={getReturnUrl(this.props.location.query['return_to'], this.props.location.hash)}
/>
);
}
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import {
+ isRelativeUrl,
getComponentIssuesUrl,
getComponentDrilldownUrl,
getPathUrlAsString,
getProjectUrl,
getQualityGatesUrl,
- getQualityGateUrl
+ getQualityGateUrl,
+ getReturnUrl
} from '../urls';
const SIMPLE_COMPONENT_KEY = 'sonarqube';
});
});
});
+
+describe('#getReturnUrl', () => {
+ it('should get the return url', () => {
+ expect(getReturnUrl('/test')).toBe('/test');
+ expect(getReturnUrl('http://www.google.com')).toBe('/');
+ expect(getReturnUrl()).toBe('/');
+ });
+});
+
+describe('#isRelativeUrl', () => {
+ it('should check a relative url', () => {
+ expect(isRelativeUrl('/test')).toBeTruthy();
+ expect(isRelativeUrl('http://www.google.com')).toBeFalsy();
+ expect(isRelativeUrl('javascript:alert("test")')).toBeFalsy();
+ expect(isRelativeUrl('\\test')).toBeFalsy();
+ expect(isRelativeUrl('//test')).toBeFalsy();
+ });
+});
export function getCodeUrl(project: string, branch?: string, selected?: string) {
return { pathname: '/code', query: { id: project, branch, selected } };
}
+
+export function getReturnUrl(returnTo?: string, hash?: string) {
+ if (isRelativeUrl(returnTo)) {
+ return returnTo + (hash ? hash : '');
+ }
+ return getBaseUrl() + '/';
+}
+
+export function isRelativeUrl(url?: string): boolean {
+ const regex = new RegExp(/^\/[^/\\]/);
+ return Boolean(url && regex.test(url));
+}