From 0631151e08174fffbc5bf3f646ef32e16e2c5145 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Fri, 28 Dec 2007 23:19:03 +0000 Subject: * Patch from Melanie provides Util.CleanString and uses it on the prim name and description. Thanks Melanie. --- OpenSim/Framework/Util.cs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index e6512c2..08b3a9d 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -222,10 +222,7 @@ namespace OpenSim.Framework output.Append(": "); } - if (bytes[bytes.Length - 1] == 0x00) - output.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1)); - else - output.Append(UTF8Encoding.UTF8.GetString(bytes)); + output.Append(CleanString(UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1))); } else { @@ -406,5 +403,31 @@ namespace OpenSim.Framework { return lluuid.UUID.ToString("n"); } + + public static string CleanString(string input) + { + if(input.Length == 0) + return input; + + int clip=input.Length; + + // Test for ++ string terminator + int pos=input.IndexOf("\0"); + if(pos != -1 && pos < clip) + clip=pos; + + // Test for CR + pos=input.IndexOf("\r"); + if(pos != -1 && pos < clip) + clip=pos; + + // Test for LF + pos=input.IndexOf("\n"); + if(pos != -1 && pos < clip) + clip=pos; + + // Truncate string before first end-of-line character found + return input.Substring(0, clip); + } } -} \ No newline at end of file +} -- cgit v1.1