mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Removed the script tag parsing from the bbcode parser.
This commit is contained in:
parent
b8969af324
commit
15077110e2
@ -414,103 +414,28 @@ BBCodeParserTag::~BBCodeParserTag() {
|
|||||||
void BBCodeParser::parse(const String &data) {
|
void BBCodeParser::parse(const String &data) {
|
||||||
Vector<BBCodeParserTag *> tags;
|
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
|
// split into tags
|
||||||
for (int i = 0; i < data.size(); ++i) {
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
if (state == STATE_NONE) {
|
if (data[i] == '<') {
|
||||||
if (data[i] == '<') {
|
// tag
|
||||||
// tag
|
for (int j = i + 1; j < data.size(); ++j) {
|
||||||
|
if (data[j] == '>') {
|
||||||
|
BBCodeParserTag *t = new BBCodeParserTag();
|
||||||
|
|
||||||
if (data.is_word_at(i, "<script")) {
|
t->data = data.substr(i, j - i + 1);
|
||||||
// after the opening <script> tag, the parser goes to data1 state
|
t->process();
|
||||||
state = STATE_DATA_1;
|
|
||||||
// no else, we need to process the tag istelf!
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = i + 1; j < data.size(); ++j) {
|
tags.push_back(t);
|
||||||
if (data[j] == '>') {
|
|
||||||
BBCodeParserTag *t = new BBCodeParserTag();
|
|
||||||
|
|
||||||
t->data = data.substr(i, j - i + 1);
|
i = j;
|
||||||
t->process();
|
break;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// script tag content
|
// content
|
||||||
|
|
||||||
bool done = false;
|
for (int j = i + 1; j < data.size(); ++j) {
|
||||||
for (int j = i; j < data.size(); ++j) {
|
if (data[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;
|
|
||||||
BBCodeParserTag *t = new BBCodeParserTag();
|
BBCodeParserTag *t = new BBCodeParserTag();
|
||||||
|
|
||||||
t->data = data.substr(i, j - i);
|
t->data = data.substr(i, j - i);
|
||||||
|
Loading…
Reference in New Issue
Block a user