Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Wayne 13 posts 33 karma points
    Oct 05, 2009 @ 17:36
    Wayne
    0

    Maybe a bug in surround()

    Hi Douglas,

    First I want to say thanks for your great search component.I think it is a must-have package of Umbraco.

    When I using it on my site, I found a issue with the surround() function.

    For example, search for 'a s' (which means 'a' and 's'), the descriptions of the search results will break.

    The word 'Bag' in description will become B<<strong>s</strong>trong>a</<strong>s</strong>trong>g. I guess that is because the surround() function replaces the 's' character with <strong>s</strong> recursively.

    Windows XP Sp3 / UltraDev Cassini 2.0 / ASP.net 2.0 / Umbraco 4.0.2.1

     

  • Wayne 13 posts 33 karma points
    Oct 05, 2009 @ 17:37
    Wayne
    0

    Sorry, forget to say the issue is with the XSLTSearch 2.8.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 05, 2009 @ 18:19
    Douglas Robar
    0

    Thanks for the bug report. I'll check into it!

    cheers,
    doug.

  • Wayne 13 posts 33 karma points
    Oct 05, 2009 @ 18:51
    Wayne
    0

    I have wrote a fix for the issue. The fix is based on an assumption that there are no '\x01' and '\x02' characters in search phase and description of search result. Wish it helps.

    Regards,

    Wayne

     

        public string surround(string data, string find, string before, string after)
        {
            // strong marks
            string s = "\x01";
            string e = "\x02";

            // searches for find within data, then surrounds it with before and after tags
            // note: replace with the actual text found, to preserve the case

            string nextWord = getFirstElement(find, " ");
            string remainingWords = find;
            while (nextWord != "")
            {
                int index = data.ToLower().IndexOf(nextWord.ToLower());
                while (index > -1)
                {
                    string replacement = s + data.Substring(index, nextWord.Length) + e;
                    data = data.Substring(0, index) + replacement + data.Substring(index + nextWord.Length);
                    index = data.ToLower().IndexOf(nextWord.ToLower(), index + replacement.Length);
                }
                remainingWords = removeFirstElement(remainingWords, " ");
                nextWord = getFirstElement(remainingWords, " ");
            }
            return data.Replace(s, before).Replace(e, after);
        }
Please Sign in or register to post replies

Write your reply to:

Draft