From 345ddcd0d82b15afa790ede4c1e8d93361a0d405 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 5 Nov 2009 18:53:25 +0000
Subject: * Escape / character when saving items and folders in an iar so that
the loader doesn't barf
---
.../Inventory/Archiver/InventoryArchiveReadRequest.cs | 13 +++++++++++--
.../Inventory/Archiver/InventoryArchiveWriteRequest.cs | 7 +++++++
2 files changed, 18 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
index f761bf0..7abaac0 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
@@ -161,14 +161,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
failedAssetRestores++;
}
else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
- {
+ {
InventoryFolderBase foundFolder
= ReplicateArchivePathToUserInventory(
filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
rootDestinationFolder, foldersCreated, nodesLoaded);
if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
- {
+ {
+ // Escape back characters
+ filePath = filePath.Replace("/", "/");
+ filePath = filePath.Replace("&", "&");
+
InventoryItemBase item = UserInventoryItemSerializer.Deserialize(data);
// Don't use the item ID that's in the file
@@ -289,6 +293,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
string newFolderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
+
+ // Escape back characters
+ newFolderName = newFolderName.Replace("/", "/");
+ newFolderName = newFolderName.Replace("&", "&");
+
UUID newFolderId = UUID.Random();
// Asset type has to be Unknown here rather than Folder, otherwise the created folder can't be
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
index 499c552..af0b72f 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
@@ -394,6 +394,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
public static string CreateArchiveFolderName(string name, UUID id)
{
+ // Only encode ampersands (for escaping anything) and / (since this is used as general dir separator).
+ name = name.Replace("&", "&");
+ name = name.Replace("/", "/");
+
return string.Format(
"{0}{1}{2}/",
name,
@@ -409,6 +413,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
public static string CreateArchiveItemName(string name, UUID id)
{
+ name = name.Replace("&", "&");
+ name = name.Replace("/", "/");
+
return string.Format(
"{0}{1}{2}.xml",
name,
--
cgit v1.1
From 6f4a588397d5e96e9566c9b34f8be2cb3ef421a4 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 5 Nov 2009 19:09:32 +0000
Subject: minor test var name tweak
---
.../Inventory/Archiver/Tests/InventoryArchiverTests.cs | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index b0fdcd6..81c3b74 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -136,7 +136,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
item1.Folder = objsFolder.ID;
- scene.AddInventoryItem(userId, item1);
+ scene.AddInventoryItem(userId, item1);
MemoryStream archiveWriteStream = new MemoryStream();
archiverModule.OnInventoryArchiveSaved += SaveCompleted;
@@ -218,14 +218,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
string userItemCreatorLastName = "Lucan";
UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
- string itemName = "b.lsl";
- string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random());
+ string item1Name = "b.lsl";
+ string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1Name, UUID.Random());
MemoryStream archiveWriteStream = new MemoryStream();
TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);
InventoryItemBase item1 = new InventoryItemBase();
- item1.Name = itemName;
+ item1.Name = item1Name;
item1.AssetID = UUID.Random();
item1.GroupID = UUID.Random();
item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName);
@@ -259,7 +259,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
= scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
InventoryItemBase foundItem1
- = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, itemName);
+ = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, item1Name);
Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
Assert.That(
@@ -277,7 +277,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
archiverModule.DearchiveInventory(userFirstName, userLastName, "xA", "meowfood", archiveReadStream);
InventoryItemBase foundItem2
- = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xA/" + itemName);
+ = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xA/" + item1Name);
Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2");
// Now try loading to a more deeply nested folder
@@ -286,7 +286,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
archiverModule.DearchiveInventory(userFirstName, userLastName, "xB/xC", "meowfood", archiveReadStream);
InventoryItemBase foundItem3
- = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC/" + itemName);
+ = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC/" + item1Name);
Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
}
--
cgit v1.1
From f8f1e94cf88fe5894366b1b11ebc3c000078cb2a Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 5 Nov 2009 19:32:24 +0000
Subject: add unit test for iar & escaping
---
.../Archiver/Tests/InventoryArchiverTests.cs | 96 +++++++++++++++++++++-
1 file changed, 94 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index 81c3b74..c366150 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -290,6 +290,98 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
}
+ [Test]
+ public void TestIarV0_1WithEscapedChars()
+ {
+ TestHelper.InMethod();
+ log4net.Config.XmlConfigurator.Configure();
+
+ string itemName = "You & you are a mean man";
+ string userPassword = "meowfood";
+
+ InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
+
+ Scene scene = SceneSetupHelpers.SetupScene("Inventory");
+ SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
+ CommunicationsManager cm = scene.CommsManager;
+
+ // Create user
+ string userFirstName = "Jock";
+ string userLastName = "Stirrup";
+ UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
+
+ lock (this)
+ {
+ UserProfileTestUtils.CreateUserWithInventory(
+ cm, userFirstName, userLastName, userPassword, userId, InventoryReceived);
+ Monitor.Wait(this, 60000);
+ }
+
+ // Create asset
+ SceneObjectGroup object1;
+ SceneObjectPart part1;
+ {
+ string partName = "part name";
+ UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
+ PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
+ Vector3 groupPosition = new Vector3(10, 20, 30);
+ Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
+ Vector3 offsetPosition = new Vector3(5, 10, 15);
+
+ part1
+ = new SceneObjectPart(
+ ownerId, shape, groupPosition, rotationOffset, offsetPosition);
+ part1.Name = partName;
+
+ object1 = new SceneObjectGroup(part1);
+ scene.AddNewSceneObject(object1, false);
+ }
+
+ UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
+ AssetBase asset1 = new AssetBase();
+ asset1.FullID = asset1Id;
+ asset1.Data = Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(object1));
+ scene.AssetService.Store(asset1);
+
+ // Create item
+ UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
+ InventoryItemBase item1 = new InventoryItemBase();
+ item1.Name = itemName;
+ item1.AssetID = asset1.FullID;
+ item1.ID = item1Id;
+ InventoryFolderBase objsFolder
+ = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
+ item1.Folder = objsFolder.ID;
+ scene.AddInventoryItem(userId, item1);
+
+ MemoryStream archiveWriteStream = new MemoryStream();
+ archiverModule.OnInventoryArchiveSaved += SaveCompleted;
+
+ mre.Reset();
+ archiverModule.ArchiveInventory(
+ Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
+ mre.WaitOne(60000, false);
+
+ /// LOAD ITEM
+ MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
+
+ archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream);
+
+ CachedUserInfo userInfo
+ = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
+
+ InventoryItemBase foundItem1
+ = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userId, "Scripts/Objects/" + itemName);
+
+ Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
+// Assert.That(
+// foundItem1.CreatorId, Is.EqualTo(userUuid),
+// "Loaded item non-uuid creator doesn't match that of the loading user");
+ Assert.That(
+ foundItem1.Name, Is.EqualTo(itemName),
+ "Loaded item name doesn't match saved name");
+ }
+
///
/// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where
/// embedded creators do not exist in the system
@@ -302,7 +394,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
{
TestHelper.InMethod();
- log4net.Config.XmlConfigurator.Configure();
+ //log4net.Config.XmlConfigurator.Configure();
string userFirstName = "Charlie";
string userLastName = "Chan";
@@ -370,7 +462,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
{
TestHelper.InMethod();
- log4net.Config.XmlConfigurator.Configure();
+ //log4net.Config.XmlConfigurator.Configure();
string userFirstName = "Dennis";
string userLastName = "Menace";
--
cgit v1.1