-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Same tag issue #4
Comments
void GetNestedEndTag(ref BBCodeNodePosition nodePos, string assumedCloseTag, in string bbCode) {
//nodePos.CloseTagStart = bbCode.IndexOf(assumedCloseTag, nodePos.OpenTagEnd, StringComparison.InvariantCultureIgnoreCase);
// Keep open to match any arguments
string lowerOpenTag = $"[{nodePos.Node.TagName.ToLower()}";
string lowerAssumedCloseTag = assumedCloseTag.ToLower();
int endTagSearchStartPos = nodePos.OpenTagEnd;
bool openCloseTagsMatch = false;
while (!openCloseTagsMatch) {
// By ignoring cases, bbcodes like [QUOTE]abc[/quote] got matched correctly, Search only for end tags based on open tags. This is enough since bbcode would be invalid
// if tags inside doesn't match. And we can't search for all non closing tags since some tags were not closed like [hr] and we got false positive matches.
int closeTagStart = bbCode.IndexOf(assumedCloseTag, endTagSearchStartPos, StringComparison.InvariantCultureIgnoreCase);
if (closeTagStart == -1) {
// Happens if no closing tag could be found. Mostly false positive matches like "[Help] XYZ not working", smileys and so on
break;
}
nodePos.CloseTagStart = closeTagStart;
nodePos.CloseTagEnd = closeTagStart + assumedCloseTag.Length;
string contentLower = bbCode.Substring(nodePos.OpenTagStart, nodePos.CloseTagEnd - nodePos.OpenTagStart);
// .NET Standard doesn't support the simple Split(string delimiter) overload, but it seems we can use the following overload without any issues
int openTagsCount = contentLower.Split(new string[] { lowerOpenTag }, StringSplitOptions.None).Length - 1;
int closeTagsCount = contentLower.Split(new string[] { lowerAssumedCloseTag }, StringSplitOptions.None).Length - 1;
openCloseTagsMatch = openTagsCount == closeTagsCount;
endTagSearchStartPos = nodePos.CloseTagStart + 1;
}
} How about changing the contentLower.Split part to a regular expression pattern? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
I'm having a problem using bbcode parser
The problem is that [b] and [bookblock] in the above case are recognized as the same tag.
The text was updated successfully, but these errors were encountered: