This project is read-only.


parser errors


if i just pass in a [ it will error. How do i prevent errors like this?


tmarman wrote Jun 2, 2010 at 1:10 PM

I'm having the same issue. Is there any way to just have unrecognized tags passed back an an escaped version of the tag?

Dood wrote Sep 21, 2010 at 10:46 PM

Here's a work around that I've created. I really suggest to the developers of this BBCode parser that they implement ways to overlook errors on unclosed or unrecognized tags. Since most people use a BBCode parser for user submitted input, the likelihood of there being rogue '[' or ']' characters or broken tags, is very large.

I would suggest the tool skip converting that which it does not understand, or at least give the option to.

The following method escapes '[' and ']' characters that do not match the predefined set of bbcode tags:

public static string ConvertBBCode(string bbCode)
string cancelledOpenBracket = "##3CEB6573-DBC0-4CBE-A053-DF9228D5B3E4##";
string cancelledCloseBracket = "##FE8C2990-B539-4E3F-AE20-C26B2797A4BB##";
//cancel non-recognized tags

bbCode = Regex.Replace(bbCode,
    cancelledOpenBracket, RegexOptions.IgnoreCase);

bbCode = Regex.Replace(bbCode,
    cancelledCloseBracket, RegexOptions.IgnoreCase);

BBCodeParser parser = new BBCodeParser(new[]
        new BBTag("b", "<b>", "</b>"), 
        new BBTag("i", "<span style=\"font-style:italic;\">", "</span>"), 
        new BBTag("u", "<span style=\"text-decoration:underline;\">", "</span>"), 
        new BBTag("code", "<code>", "</code>"), 
        new BBTag("quote", "<blockquote>", "</blockquote>"), 
        new BBTag("list=1", "<ol>", "</ol>"), 
        new BBTag("list", "<ul>", "</ul>"), 
        new BBTag("*", "<li>", "</li>", true, false)

bbCode = parser.Transform(bbCode);
bbCode = Regex.Replace(bbCode, cancelledOpenBracket, "[");
bbCode = Regex.Replace(bbCode, cancelledCloseBracket, "]");
return bbCode;

If you support a different set of BBCode tags, you will have to adjust the regular expressions to work with your set of tags.

wrote Sep 22, 2010 at 7:22 PM

wrote Sep 27, 2010 at 12:46 PM

mitchellj wrote Sep 27, 2010 at 12:47 PM

I would also love the ability to ignore unrecognized tags and pass them back as escaped or something. But already fantatsic work, a little work around is still much better than having to do an entire code parser using Regex.

codekicker wrote Jun 21, 2011 at 11:53 AM

The solution is to use ErrorMode.ErrorFree. This mode will skip over all errors and allow for example array indexing strings.

wrote Sep 29, 2011 at 9:09 PM

wrote Feb 14, 2013 at 3:41 AM

wrote May 16, 2013 at 8:20 AM

wrote May 16, 2013 at 8:20 AM

wrote Jun 14, 2013 at 7:53 AM