Removed the script tag parsing from the bbcode parser.

This commit is contained in:
Relintai 2022-02-04 05:51:53 +01:00
parent b8969af324
commit 15077110e2

View File

@ -414,103 +414,28 @@ BBCodeParserTag::~BBCodeParserTag() {
void BBCodeParser::parse(const String &data) {
Vector<BBCodeParserTag *> tags;
// <script> content parsing is based on https://stackoverflow.com/questions/14574471/how-do-browsers-parse-a-script-tag-exactly
const int STATE_NONE = 0;
const int STATE_DATA_1 = 1;
const int STATE_DATA_2 = 2;
const int STATE_DATA_3 = 3;
int state = STATE_NONE;
// split into tags
for (int i = 0; i < data.size(); ++i) {
if (state == STATE_NONE) {
if (data[i] == '<') {
// tag
if (data[i] == '<') {
// tag
for (int j = i + 1; j < data.size(); ++j) {
if (data[j] == '>') {
BBCodeParserTag *t = new BBCodeParserTag();
if (data.is_word_at(i, "<script")) {
// after the opening <script> tag, the parser goes to data1 state
state = STATE_DATA_1;
// no else, we need to process the tag istelf!
}
t->data = data.substr(i, j - i + 1);
t->process();
for (int j = i + 1; j < data.size(); ++j) {
if (data[j] == '>') {
BBCodeParserTag *t = new BBCodeParserTag();
tags.push_back(t);
t->data = data.substr(i, j - i + 1);
t->process();
tags.push_back(t);
i = j;
break;
}
}
} else {
// content
for (int j = i + 1; j < data.size(); ++j) {
if (data[j] == '<') {
BBCodeParserTag *t = new BBCodeParserTag();
t->data = data.substr(i, j - i);
t->type = BBCodeParserTag::BBCODE_PARSER_TAG_TYPE_CONTENT;
tags.push_back(t);
i = j - 1;
break;
}
i = j;
break;
}
}
} else {
// script tag content
// content
bool done = false;
for (int j = i; j < data.size(); ++j) {
char c = data[j];
if (c != '<' && c != '-') {
continue;
}
if (data.is_word_at(j, "-->")) {
// if --> is encountered while in any state, switch to data1 state
state = STATE_DATA_1;
continue;
}
if (state == STATE_DATA_1) {
if (data.is_word_at(j, "<!--")) {
// if <!-- is encountered while in data1 state, switch to data2 state
state = STATE_DATA_2;
} else if (data.is_word_at(j, "</script")) {
// if </script[\s/>] is encountered while in any other state (than data3), stop parsing
done = true;
}
} else if (state == STATE_DATA_2) {
if (data.is_word_at(j, "<script")) {
// if <script[\s/>] is encountered while in data2 state, switch to data3 state
state = STATE_DATA_3;
} else if (data.is_word_at(j, "</script")) {
// if </script[\s/>] is encountered while in any other state (than data3), stop parsing
done = true;
}
} else if (state == STATE_DATA_3) {
// if </script[\s/>] is encountered while in data3 state, switch to data2 state
if (data.is_word_at(j, "</script")) {
state = STATE_DATA_2;
}
}
if (done) {
state = STATE_NONE;
for (int j = i + 1; j < data.size(); ++j) {
if (data[j] == '<') {
BBCodeParserTag *t = new BBCodeParserTag();
t->data = data.substr(i, j - i);