From 499f1428f707cbb116349dc0a2f07a19658df668 Mon Sep 17 00:00:00 2001 From: Homer Horwitz Date: Sun, 2 Nov 2008 13:07:57 +0000 Subject: - Add Util.isUUID - Add tests for Util.isUUID - First part of the fix for protocol interoperability between viewer 1.20 and 1.21 for friend offers. --- OpenSim/Framework/Tests/UtilTest.cs | 15 +++++++++++++++ OpenSim/Framework/Util.cs | 7 +++++++ 2 files changed, 22 insertions(+) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Tests/UtilTest.cs b/OpenSim/Framework/Tests/UtilTest.cs index a973ed2..0224356 100644 --- a/OpenSim/Framework/Tests/UtilTest.cs +++ b/OpenSim/Framework/Tests/UtilTest.cs @@ -137,5 +137,20 @@ namespace OpenSim.Framework.Tests "Normalized vector generated from vector does not have magnitude of 1."); } } + + [Test] + public void UUIDTests() + { + Assert.IsTrue(Util.isUUID("01234567-89ab-Cdef-0123-456789AbCdEf"), + "A correct UUID wasn't recognized."); + Assert.IsFalse(Util.isUUID("FOOBAR67-89ab-Cdef-0123-456789AbCdEf"), + "UUIDs with non-hex characters are recognized as correct UUIDs."); + Assert.IsFalse(Util.isUUID("01234567"), + "Too short UUIDs are regognized as correct UUIDs."); + Assert.IsFalse(Util.isUUID("01234567-89ab-Cdef-0123-456789AbCdEf0"), + "Too long UUIDs are regognized as correct UUIDs."); + Assert.IsFalse(Util.isUUID("01234567-89ab-Cdef-0123+456789AbCdEf"), + "UUIDs with wrong format are recognized as correct UUIDs."); + } } } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index c5334a8..b8080ec 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -64,6 +64,8 @@ namespace OpenSim.Framework private static readonly DateTime unixEpoch = DateTime.ParseExact("1970-01-01 00:00:00 +0", "yyyy-MM-dd hh:mm:ss z", DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); + private static readonly Regex UUIDPattern = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); + #region Vector Equations /// @@ -796,5 +798,10 @@ namespace OpenSim.Framework x += rx; y += ry; } + + public static bool isUUID(string s) + { + return UUIDPattern.IsMatch(s); + } } } -- cgit v1.1