mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Subpath: Add check for url being same as subpath on stripBaseFromUrl (#75670)
* Subpath: Add check for url being same as subpath * Better comment
This commit is contained in:
parent
5ba37068c2
commit
59f0f9a93e
@ -54,6 +54,10 @@ describe('locationUtil', () => {
|
|||||||
const urlWithoutMaster = locationUtil.stripBaseFromUrl('/subUrl-backup/thisShouldRemain/');
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('/subUrl-backup/thisShouldRemain/');
|
||||||
expect(urlWithoutMaster).toBe('/subUrl-backup/thisShouldRemain/');
|
expect(urlWithoutMaster).toBe('/subUrl-backup/thisShouldRemain/');
|
||||||
});
|
});
|
||||||
|
test('relative url with same url', () => {
|
||||||
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('/subUrl');
|
||||||
|
expect(urlWithoutMaster).toBe('');
|
||||||
|
});
|
||||||
test('absolute url', () => {
|
test('absolute url', () => {
|
||||||
const urlWithoutMaster = locationUtil.stripBaseFromUrl('http://www.domain.com:9877/subUrl/thisShouldRemain/');
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('http://www.domain.com:9877/subUrl/thisShouldRemain/');
|
||||||
expect(urlWithoutMaster).toBe('/thisShouldRemain/');
|
expect(urlWithoutMaster).toBe('/thisShouldRemain/');
|
||||||
@ -74,6 +78,10 @@ describe('locationUtil', () => {
|
|||||||
);
|
);
|
||||||
expect(urlWithoutMaster).toBe('http://www.domain.com:9877/subUrl-backup/thisShouldRemain/');
|
expect(urlWithoutMaster).toBe('http://www.domain.com:9877/subUrl-backup/thisShouldRemain/');
|
||||||
});
|
});
|
||||||
|
test('absolute url with same url', () => {
|
||||||
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('http://www.domain.com:9877/subUrl');
|
||||||
|
expect(urlWithoutMaster).toBe('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when appSubUrl not configured', () => {
|
describe('when appSubUrl not configured', () => {
|
||||||
|
@ -43,9 +43,10 @@ const stripBaseFromUrl = (urlOrPath: string): string => {
|
|||||||
segmentToStrip = `${window.location.origin}${appSubUrl}`;
|
segmentToStrip = `${window.location.origin}${appSubUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the segment is followed by a '/' so it does not replace incorrect similarly named segments
|
// Check if the segment is either exactly the same as the url
|
||||||
|
// or followed by a '/' so it does not replace incorrect similarly named segments
|
||||||
// i.e. /grafana should not replace /grafanadashboards
|
// i.e. /grafana should not replace /grafanadashboards
|
||||||
return urlOrPath.length > 0 && urlOrPath.indexOf(segmentToStrip + '/') === 0
|
return urlOrPath.length > 0 && (urlOrPath.indexOf(segmentToStrip + '/') === 0 || urlOrPath === segmentToStrip)
|
||||||
? urlOrPath.slice(segmentToStrip.length - stripExtraChars)
|
? urlOrPath.slice(segmentToStrip.length - stripExtraChars)
|
||||||
: urlOrPath;
|
: urlOrPath;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user