Skip to content

Commit 559e843

Browse files
committed
"Cleanse" language tag - somebody managed to put newline into multiple fields
1 parent f3e5578 commit 559e843

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
1414

1515
# Project version number
1616
set(PRJ_VERSION_MAJOR 9)
17-
set(PRJ_VERSION_MINOR 42)
17+
set(PRJ_VERSION_MINOR 43)
1818
configure_file("${PROJECT_SOURCE_DIR}/cmake/version.h.in" "${PROJECT_BINARY_DIR}/version.h")
1919
include_directories("${PROJECT_BINARY_DIR}")
2020

lib2inpx/lib2inpx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ void process_book(const mysql_connection& mysql, MYSQL_ROW record, const string&
655655
string book_type(record[3]);
656656
string book_deleted(record[4]);
657657
string book_time(record[5]);
658-
string book_lang(record[6]);
658+
string book_lang(cleanse_lang(record[6]));
659659
string book_kwds = (record[7] == NULL) ? "" : fix_data(cleanse(record[7]), g_limits.KeyWords);
660660

661661
string book_md5;

lib2inpx/util.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ string cleanse(const string& s)
151151
return str;
152152
}
153153

154+
string cleanse_lang(const string& s)
155+
{
156+
string str(s);
157+
boost::algorithm::erase_all(str, "\r");
158+
boost::algorithm::erase_all(str, "\n");
159+
boost::algorithm::trim_right(str);
160+
boost::algorithm::trim_left(str);
161+
return str;
162+
}
163+
154164
string duplicate_quote(const string& str) { return boost::algorithm::replace_all_copy(str, "\'", "\'\'"); }
155165

156166
#endif // DO_NOT_INCLUDE_PARSER
@@ -622,7 +632,7 @@ void fb2_parser::on_book_title(const std::string& str, const attributes_t& attrs
622632

623633
void fb2_parser::on_keywords(const std::string& str, const attributes_t& attrs) { m_keywords = fix_data(cleanse(str), g_limits.KeyWords); }
624634

625-
void fb2_parser::on_lang(const std::string& str, const attributes_t& attrs) { m_language = str; }
635+
void fb2_parser::on_lang(const std::string& str, const attributes_t& attrs) { m_language = cleanse_lang(str); }
626636

627637
void fb2_parser::on_sequence(const std::string& str, const attributes_t& attrs)
628638
{

lib2inpx/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern bool g_fix;
2525
void initialize_limits(const std::string& config);
2626
std::string fix_data(const std::string& str, size_t max_len);
2727
std::string cleanse(const std::string& s);
28+
std::string cleanse_lang(const std::string& s);
2829

2930
#endif // DO_NOT_INCLUDE_PARSER
3031

0 commit comments

Comments
 (0)