Fix article metadata parser

Fixed an issue which would cause the metadata parser to partially read
lines that were supposed to be ignored (comment lines).
This commit is contained in:
luca0N! 2022-04-27 20:39:13 -03:00
parent 44cd6dc1d6
commit 2cf3706a83
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 18 additions and 2 deletions

View File

@ -50,13 +50,21 @@ namespace Article {
size_t det_article_pos = 0;
bool reading_metadata = false,
done = false,
skip = false;
skip = false,
ignore_line = false;
std::list<std::string> cfg_lines = { "" };
while (fgets(buf, buflen, a) != NULL) {
// Ignore blank lines or lines starting with a comment.
if (buf[0] == '\n' || buf[0] == '#') continue;
if (buf[0] == '#') {
ignore_line = true;
continue;
} else if (buf[0] == '\n') {
if (ignore_line)
ignore_line = false;
continue;
}
int eol = -1;
for (int c = 0; c < buflen; c++) {
// Check if this loop has already done what it's supposed to do by checking if the title has been set.
@ -93,6 +101,13 @@ namespace Article {
if (skip) { skip = false; continue; }
if (done) break;
if (reading_metadata) {
if (ignore_line && eol == -1)
continue;
else if (ignore_line && eol > -1) {
ignore_line = false;
cfg_lines.insert(cfg_lines.end(), "");
continue;
}
if (eol > -1) {
buf[eol] = '\0';
*(--cfg_lines.end()) += buf;
@ -104,6 +119,7 @@ namespace Article {
bool reading_article_metadata = false;
for (std::string const &line : cfg_lines) {
std::cout << "[!] " << line << "\n";
// Check namespace
if (reading_article_metadata) {
std::string k_title = "Title=",