From 4d8eb956011fc5883b8fa4fa5a904d0d1d632410 Mon Sep 17 00:00:00 2001 From: Kevin Cozens Date: Mon, 9 Dec 2013 03:15:40 -0500 Subject: [PATCH] ParseNotecardToList() returned data past end of notecard text (mantis #6881). --- OpenSim/Framework/SLUtil.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index 537de7ab15..cb73e8f762 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -247,12 +247,18 @@ namespace OpenSim.Framework /// public static List ParseNotecardToList(string rawInput) { - string[] input = rawInput.Replace("\r", "").Split('\n'); + string[] input; int idx = 0; int level = 0; List output = new List(); string[] words; + //The Linden format always ends with a } after the input data. + //Strip off trailing } so there is nothing after the input data. + int i = rawInput.LastIndexOf("}"); + rawInput = rawInput.Remove(i, rawInput.Length-i); + input = rawInput.Replace("\r", "").Split('\n'); + while (idx < input.Length) { if (input[idx] == "{") @@ -287,24 +293,18 @@ namespace OpenSim.Framework break; if (words[0] == "Text") { - int len = int.Parse(words[2]); - idx++; + idx++; //Now points to first line of notecard text - int count = -1; + //Number of lines in notecard. + int lines = input.Length - idx; + int line = 0; - while (count < len && idx < input.Length) + while (line < lines) { - // int l = input[idx].Length; - string ln = input[idx]; - - int need = len-count-1; - if (ln.Length > need) - ln = ln.Substring(0, need); - -// m_log.DebugFormat("[PARSE NOTECARD]: Adding line {0}", ln); - output.Add(ln); - count += ln.Length + 1; +// m_log.DebugFormat("[PARSE NOTECARD]: Adding line {0}", input[idx]); + output.Add(input[idx]); idx++; + line++; } return output;