mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Subpath: On stripBaseFromUrl, check if the segmentToStrip is followed by a '/' otherwise dont replace it (#75559)
This commit is contained in:
parent
96cbe70b14
commit
8eadc94d3e
@ -50,6 +50,10 @@ describe('locationUtil', () => {
|
|||||||
const urlWithoutMaster = locationUtil.stripBaseFromUrl('/thisShouldRemain/subUrl/');
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('/thisShouldRemain/subUrl/');
|
||||||
expect(urlWithoutMaster).toBe('/thisShouldRemain/subUrl/');
|
expect(urlWithoutMaster).toBe('/thisShouldRemain/subUrl/');
|
||||||
});
|
});
|
||||||
|
test('relative url with similar suburl', () => {
|
||||||
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('/subUrl-backup/thisShouldRemain/');
|
||||||
|
expect(urlWithoutMaster).toBe('/subUrl-backup/thisShouldRemain/');
|
||||||
|
});
|
||||||
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/');
|
||||||
@ -64,6 +68,12 @@ describe('locationUtil', () => {
|
|||||||
const urlWithoutMaster = locationUtil.stripBaseFromUrl('http://www.domain.com:9877/thisShouldRemain/subUrl/');
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl('http://www.domain.com:9877/thisShouldRemain/subUrl/');
|
||||||
expect(urlWithoutMaster).toBe('http://www.domain.com:9877/thisShouldRemain/subUrl/');
|
expect(urlWithoutMaster).toBe('http://www.domain.com:9877/thisShouldRemain/subUrl/');
|
||||||
});
|
});
|
||||||
|
test('absolute url with similar suburl', () => {
|
||||||
|
const urlWithoutMaster = locationUtil.stripBaseFromUrl(
|
||||||
|
'http://www.domain.com:9877/subUrl-backup/thisShouldRemain/'
|
||||||
|
);
|
||||||
|
expect(urlWithoutMaster).toBe('http://www.domain.com:9877/subUrl-backup/thisShouldRemain/');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when appSubUrl not configured', () => {
|
describe('when appSubUrl not configured', () => {
|
||||||
|
@ -43,7 +43,9 @@ const stripBaseFromUrl = (urlOrPath: string): string => {
|
|||||||
segmentToStrip = `${window.location.origin}${appSubUrl}`;
|
segmentToStrip = `${window.location.origin}${appSubUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlOrPath.length > 0 && urlOrPath.indexOf(segmentToStrip) === 0
|
// Check if the segment is followed by a '/' so it does not replace incorrect similarly named segments
|
||||||
|
// i.e. /grafana should not replace /grafanadashboards
|
||||||
|
return urlOrPath.length > 0 && urlOrPath.indexOf(segmentToStrip + '/') === 0
|
||||||
? urlOrPath.slice(segmentToStrip.length - stripExtraChars)
|
? urlOrPath.slice(segmentToStrip.length - stripExtraChars)
|
||||||
: urlOrPath;
|
: urlOrPath;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user