aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/helpers
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-10-12 11:43:36 +0200
committerSonarTech <sonartech@sonarsource.com>2018-10-15 11:53:17 +0200
commit9bbbcdb26eb2e88aa53820988964341629276fc4 (patch)
tree011326c4b91f4baafbe634084e021d3c3d7fe8b8 /server/sonar-web/src/main/js/helpers
parentf37eb96fa18b2d5e080fc0187d3307125d3c31f2 (diff)
downloadsonarqube-9bbbcdb26eb2e88aa53820988964341629276fc4.tar.gz
sonarqube-9bbbcdb26eb2e88aa53820988964341629276fc4.zip
SONAR-11265 relax url validation
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts4
-rw-r--r--server/sonar-web/src/main/js/helpers/urls.ts10
2 files changed, 4 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
index bb637690f4c..0dc5a089379 100644
--- a/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
+++ b/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
@@ -162,11 +162,7 @@ describe('#isUrl', () => {
expect(isUrl('http://##')).toBeFalsy();
expect(isUrl('http://##/')).toBeFalsy();
expect(isUrl('//')).toBeFalsy();
- expect(isUrl('//a')).toBeFalsy();
- expect(isUrl('///a')).toBeFalsy();
expect(isUrl('///')).toBeFalsy();
- expect(isUrl('foo.com')).toBeFalsy();
expect(isUrl('http:// shouldfail.com')).toBeFalsy();
- expect(isUrl(':// should fail')).toBeFalsy();
});
});
diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts
index ed5834e590e..de21ce40a5e 100644
--- a/server/sonar-web/src/main/js/helpers/urls.ts
+++ b/server/sonar-web/src/main/js/helpers/urls.ts
@@ -254,15 +254,13 @@ export function getHomePageUrl(homepage: HomePage) {
}
export function isUrl(url: string) {
- if (!URL) {
+ try {
const elem = document.createElement('a');
elem.href = url;
return !!(elem.host && elem.hostname && elem.protocol);
- }
- try {
- const parsedUrl = new URL(url);
- return url.includes(parsedUrl.host);
} catch (error) {
- return false;
+ // both IE11 & Edge throw an exception when a url contains credentials
+ // is this case let's just pretend the url is fine and pass it to the server for the validation
+ return true;
}
}