diff options
author | Justin Clark-Casey (justincc) | 2009-11-09 15:49:09 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2009-11-09 15:49:09 +0000 |
commit | 668850b974fba428a527c01249e8e76619461d23 (patch) | |
tree | 7edbae7e80fe1197a908914ffb24b46178bccc56 /OpenSim | |
parent | add unit test for iar & escaping (diff) | |
download | opensim-SC_OLD-668850b974fba428a527c01249e8e76619461d23.zip opensim-SC_OLD-668850b974fba428a527c01249e8e76619461d23.tar.gz opensim-SC_OLD-668850b974fba428a527c01249e8e76619461d23.tar.bz2 opensim-SC_OLD-668850b974fba428a527c01249e8e76619461d23.tar.xz |
* for iars, allow item names/folders including "/" to be escaped using "\/"
* also, "\" has to be escaped as "\\"
* add item name unit test for escaped characters
Diffstat (limited to 'OpenSim')
3 files changed, 87 insertions, 5 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs index a822d10..e297c37 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveUtils.cs | |||
@@ -27,6 +27,9 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
30 | using OpenMetaverse; | 33 | using OpenMetaverse; |
31 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
32 | using OpenSim.Services.Interfaces; | 35 | using OpenSim.Services.Interfaces; |
@@ -38,6 +41,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
38 | /// </summary> | 41 | /// </summary> |
39 | public static class InventoryArchiveUtils | 42 | public static class InventoryArchiveUtils |
40 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
41 | public static readonly string PATH_DELIMITER = "/"; | 46 | public static readonly string PATH_DELIMITER = "/"; |
42 | 47 | ||
43 | /// <summary> | 48 | /// <summary> |
@@ -181,10 +186,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
181 | public static InventoryItemBase FindItemByPath( | 186 | public static InventoryItemBase FindItemByPath( |
182 | IInventoryService inventoryService, InventoryFolderBase startFolder, string path) | 187 | IInventoryService inventoryService, InventoryFolderBase startFolder, string path) |
183 | { | 188 | { |
184 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | 189 | string[] components = SplitEscapedPath(path); |
190 | components[0] = UnescapePath(components[0]); | ||
191 | |||
192 | //string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | ||
185 | 193 | ||
186 | if (components.Length == 1) | 194 | if (components.Length == 1) |
187 | { | 195 | { |
196 | // m_log.DebugFormat("FOUND SINGLE COMPONENT [{0}]", components[0]); | ||
197 | |||
188 | List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID); | 198 | List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID); |
189 | foreach (InventoryItemBase item in items) | 199 | foreach (InventoryItemBase item in items) |
190 | { | 200 | { |
@@ -194,6 +204,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
194 | } | 204 | } |
195 | else | 205 | else |
196 | { | 206 | { |
207 | // m_log.DebugFormat("FOUND COMPONENTS [{0}] and [{1}]", components[0], components[1]); | ||
208 | |||
197 | InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID); | 209 | InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID); |
198 | 210 | ||
199 | foreach (InventoryFolderBase folder in contents.Folders) | 211 | foreach (InventoryFolderBase folder in contents.Folders) |
@@ -206,5 +218,74 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
206 | // We didn't find an item or intermediate folder with the given name | 218 | // We didn't find an item or intermediate folder with the given name |
207 | return null; | 219 | return null; |
208 | } | 220 | } |
221 | |||
222 | /// <summary> | ||
223 | /// Split a human escaped path into two components if it contains an unescaped path delimiter, or one component | ||
224 | /// if no delimiter is present | ||
225 | /// </summary> | ||
226 | /// <param name="path"></param> | ||
227 | /// <returns> | ||
228 | /// The split path. We leave the components in their originally unescaped state (though we remove the delimiter | ||
229 | /// which originally split them if applicable). | ||
230 | /// </returns> | ||
231 | public static string[] SplitEscapedPath(string path) | ||
232 | { | ||
233 | // m_log.DebugFormat("SPLITTING PATH {0}", path); | ||
234 | |||
235 | bool singleEscapeChar = false; | ||
236 | |||
237 | for (int i = 0; i < path.Length; i++) | ||
238 | { | ||
239 | if (path[i] == '\\' && !singleEscapeChar) | ||
240 | { | ||
241 | singleEscapeChar = true; | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | if (PATH_DELIMITER == path[i].ToString() && !singleEscapeChar) | ||
246 | return new string[2] { path.Remove(i), path.Substring(i + 1) }; | ||
247 | else | ||
248 | singleEscapeChar = false; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | // We didn't find a delimiter | ||
253 | return new string[1] { path }; | ||
254 | } | ||
255 | |||
256 | /// <summary> | ||
257 | /// Unescapes a human escaped path. This means that "\\" goes to "\", and "\/" goes to "/" | ||
258 | /// </summary> | ||
259 | /// <param name="path"></param> | ||
260 | /// <returns></returns> | ||
261 | public static string UnescapePath(string path) | ||
262 | { | ||
263 | // m_log.DebugFormat("ESCAPING PATH {0}", path); | ||
264 | |||
265 | StringBuilder sb = new StringBuilder(); | ||
266 | |||
267 | bool singleEscapeChar = false; | ||
268 | for (int i = 0; i < path.Length; i++) | ||
269 | { | ||
270 | if (path[i] == '\\' && !singleEscapeChar) | ||
271 | singleEscapeChar = true; | ||
272 | else | ||
273 | singleEscapeChar = false; | ||
274 | |||
275 | if (singleEscapeChar) | ||
276 | { | ||
277 | if (PATH_DELIMITER == path[i].ToString()) | ||
278 | sb.Append(PATH_DELIMITER); | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | sb.Append(path[i]); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | // m_log.DebugFormat("ESCAPED PATH TO {0}", sb); | ||
287 | |||
288 | return sb.ToString(); | ||
289 | } | ||
209 | } | 290 | } |
210 | } \ No newline at end of file | 291 | } \ No newline at end of file |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index c366150..bcae5f5 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -296,7 +296,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
296 | TestHelper.InMethod(); | 296 | TestHelper.InMethod(); |
297 | log4net.Config.XmlConfigurator.Configure(); | 297 | log4net.Config.XmlConfigurator.Configure(); |
298 | 298 | ||
299 | string itemName = "You & you are a mean man"; | 299 | string itemName = "You & you are a mean/man/"; |
300 | string humanEscapedItemName = @"You & you are a mean\/man\/"; | ||
300 | string userPassword = "meowfood"; | 301 | string userPassword = "meowfood"; |
301 | 302 | ||
302 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | 303 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); |
@@ -362,7 +363,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
362 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | 363 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); |
363 | mre.WaitOne(60000, false); | 364 | mre.WaitOne(60000, false); |
364 | 365 | ||
365 | /// LOAD ITEM | 366 | // LOAD ITEM |
366 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | 367 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); |
367 | 368 | ||
368 | archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); | 369 | archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); |
@@ -371,7 +372,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
371 | = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | 372 | = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); |
372 | 373 | ||
373 | InventoryItemBase foundItem1 | 374 | InventoryItemBase foundItem1 |
374 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userId, "Scripts/Objects/" + itemName); | 375 | = InventoryArchiveUtils.FindItemByPath( |
376 | scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName); | ||
375 | 377 | ||
376 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | 378 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); |
377 | // Assert.That( | 379 | // Assert.That( |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 00743fc..c689aba 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | |||
@@ -93,7 +93,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
93 | 93 | ||
94 | public void AddInventoryItem(UUID AgentID, InventoryItemBase item) | 94 | public void AddInventoryItem(UUID AgentID, InventoryItemBase item) |
95 | { | 95 | { |
96 | |||
97 | if (InventoryService.AddItem(item)) | 96 | if (InventoryService.AddItem(item)) |
98 | { | 97 | { |
99 | int userlevel = 0; | 98 | int userlevel = 0; |