Permalink
Browse files

Added fix for singular tags and an edge case fix where bbsharp would …

…crash if the string ended with an opening square bracket
  • Loading branch information...
1 parent f50a09c commit 1910a7d665f158b95c892d6631f0bb98763ca328 @charliesome committed Apr 10, 2010
View
@@ -55,6 +55,16 @@ public static BBCodeDocument Load(string BBCode, bool ThrowOnError, IEnumerable<
StringBuilder TagName = new StringBuilder();
i++;
+ // edge case where there is an [ as the last character
+ if (i == BBCode.Length)
+ {
+ if (ThrowOnError)
+ throw new BBCodeParseException("Reached end of document while reading tag", i);
+ AddPlainText(document, nodestack, "[" + TagName.ToString());
+ continue;
+ }
+
+
bool IsClosing = BBCode[i] == '/';
if (IsClosing)
i++;
@@ -71,7 +81,8 @@ public static BBCodeDocument Load(string BBCode, bool ThrowOnError, IEnumerable<
{
var el = new BBCodeNode(TagName.ToString(), "", SingularTags.Contains(TagName.ToString()));
nodestack.Peek().AppendChild(el);
- nodestack.Push(el);
+ if (!el.Singular)
+ nodestack.Push(el);
if (BBCode[i] == ']')
continue;
@@ -119,7 +130,7 @@ public static BBCodeDocument Load(string BBCode, bool ThrowOnError, IEnumerable<
nodestack.Pop();
if (nodestack.Count > 0 && ThrowOnError)
- throw new BBCodeParseException("Reached end of document with " + nodestack.Count.ToString() + " unclosed tags.", BBCode.Length);
+ throw new BBCodeParseException("Reached end of document with " + (nodestack.Count-1).ToString() + " unclosed tags", BBCode.Length);
return document;
}
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 1910a7d

Please sign in to comment.