HOTFIX: the map property exitUrl now accept relative links that are deep enough to rewrite the base url

This commit is contained in:
kharhamel 2021-01-05 17:08:33 +01:00
parent 359fa3a571
commit 6caa0e5b62
2 changed files with 22 additions and 2 deletions

View File

@ -30,8 +30,12 @@ export class Room {
let roomId = ''; let roomId = '';
let hash = ''; let hash = '';
if (!identifier.startsWith('/_/') && !identifier.startsWith('/@/')) { //relative file link if (!identifier.startsWith('/_/') && !identifier.startsWith('/@/')) { //relative file link
const absoluteExitSceneUrl = new URL(identifier, baseUrl); //Relative identifier can be deep enough to rewrite the base domain, so we cannot use the variable 'baseUrl' as the actual base url for the URL objects.
roomId = '_/'+currentInstance+'/'+absoluteExitSceneUrl.hostname + absoluteExitSceneUrl.pathname; //in case of a relative url, we need to create a public roomId //We instead use 'workadventure' as a dummy base value.
const baseUrlObject = new URL(baseUrl);
const absoluteExitSceneUrl = new URL(identifier, 'http://workadventure/_/'+currentInstance+'/'+baseUrlObject.hostname+baseUrlObject.pathname);
roomId = absoluteExitSceneUrl.pathname; //in case of a relative url, we need to create a public roomId
roomId = roomId.substring(1); //remove the leading slash
hash = absoluteExitSceneUrl.hash; hash = absoluteExitSceneUrl.hash;
hash = hash.substring(1); //remove the leading diese hash = hash.substring(1); //remove the leading diese
} else { //absolute room Id } else { //absolute room Id

View File

@ -34,6 +34,22 @@ describe("Room getIdFromIdentifier()", () => {
expect(roomId).toEqual('_/global/maps.workadventu.re/floor1/Floor1.json'); expect(roomId).toEqual('_/global/maps.workadventu.re/floor1/Floor1.json');
expect(hash).toEqual(''); expect(hash).toEqual('');
}); });
it("should work with a relative file link that rewrite the map domain", () => {
const {roomId, hash} = Room.getIdFromIdentifier('../../maps.workadventure.localhost/Floor1/floor1.json', 'https://maps.workadventu.re/floor0/Floor0.json', 'global');
expect(roomId).toEqual('_/global/maps.workadventure.localhost/Floor1/floor1.json');
expect(hash).toEqual('');
});
it("should work with a relative file link that rewrite the map instance", () => {
const {roomId, hash} = Room.getIdFromIdentifier('../../../notglobal/maps.workadventu.re/Floor1/floor1.json', 'https://maps.workadventu.re/floor0/Floor0.json', 'global');
expect(roomId).toEqual('_/notglobal/maps.workadventu.re/Floor1/floor1.json');
expect(hash).toEqual('');
});
it("should work with a relative file link that change the map type", () => {
const {roomId, hash} = Room.getIdFromIdentifier('../../../../@/tcm/is/great', 'https://maps.workadventu.re/floor0/Floor0.json', 'global');
expect(roomId).toEqual('@/tcm/is/great');
expect(hash).toEqual('');
});
it("should work with a relative file link and a hash as parameters", () => { it("should work with a relative file link and a hash as parameters", () => {
const {roomId, hash} = Room.getIdFromIdentifier('./test2.json#start', 'https://maps.workadventu.re/test.json', 'global'); const {roomId, hash} = Room.getIdFromIdentifier('./test2.json#start', 'https://maps.workadventu.re/test.json', 'global');
expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json'); expect(roomId).toEqual('_/global/maps.workadventu.re/test2.json');