forked from premiere/premiere-libtorrent
extended utf-8 encoding error correction to also cover name, comment and created by. Fixes #372
This commit is contained in:
parent
e01f628b8e
commit
aecc24171d
|
@ -34,6 +34,8 @@ release 0.14.2
|
||||||
renamed file names instead of the original file names in the torrent.
|
renamed file names instead of the original file names in the torrent.
|
||||||
* documentation fix of queing section
|
* documentation fix of queing section
|
||||||
* fixed potential issue in udp_socket (affected udp tracker support)
|
* fixed potential issue in udp_socket (affected udp tracker support)
|
||||||
|
* made name, comment and created by also be subject to utf-8 error
|
||||||
|
correction (filenames already were)
|
||||||
|
|
||||||
release 0.14.1
|
release 0.14.1
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,7 @@ int main(int argc, char* argv[])
|
||||||
std::cout << "comment: " << t.comment() << "\n";
|
std::cout << "comment: " << t.comment() << "\n";
|
||||||
std::cout << "created by: " << t.creator() << "\n";
|
std::cout << "created by: " << t.creator() << "\n";
|
||||||
std::cout << "magnet link: " << make_magnet_uri(t) << "\n";
|
std::cout << "magnet link: " << make_magnet_uri(t) << "\n";
|
||||||
|
std::cout << "name: " << t.name() << "\n";
|
||||||
std::cout << "files:\n";
|
std::cout << "files:\n";
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (torrent_info::file_iterator i = t.begin_files();
|
for (torrent_info::file_iterator i = t.begin_files();
|
||||||
|
|
|
@ -75,13 +75,12 @@ namespace
|
||||||
str += 0x80 | (chr & 0x3f);
|
str += 0x80 | (chr & 0x3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void verify_encoding(file_entry& target)
|
bool verify_encoding(std::string& target)
|
||||||
{
|
{
|
||||||
std::string tmp_path;
|
std::string tmp_path;
|
||||||
std::string file_path = target.path.string();
|
|
||||||
bool valid_encoding = true;
|
bool valid_encoding = true;
|
||||||
for (std::string::iterator i = file_path.begin()
|
for (std::string::iterator i = target.begin()
|
||||||
, end(file_path.end()); i != end; ++i)
|
, end(target.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
// valid ascii-character
|
// valid ascii-character
|
||||||
if ((*i & 0x80) == 0)
|
if ((*i & 0x80) == 0)
|
||||||
|
@ -154,7 +153,14 @@ namespace
|
||||||
// save the original encoding and replace the
|
// save the original encoding and replace the
|
||||||
// commonly used path with the correctly
|
// commonly used path with the correctly
|
||||||
// encoded string
|
// encoded string
|
||||||
if (!valid_encoding) target.path = tmp_path;
|
if (!valid_encoding) target = tmp_path;
|
||||||
|
return valid_encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
void verify_encoding(file_entry& target)
|
||||||
|
{
|
||||||
|
std::string p = target.path.string();
|
||||||
|
if (!verify_encoding(p)) target.path = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void trim_path_element(std::string& path_element)
|
void trim_path_element(std::string& path_element)
|
||||||
|
@ -490,6 +496,9 @@ namespace libtorrent
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// correct utf-8 encoding errors
|
||||||
|
verify_encoding(name);
|
||||||
|
|
||||||
// extract file list
|
// extract file list
|
||||||
lazy_entry const* i = info.dict_find_list("files");
|
lazy_entry const* i = info.dict_find_list("files");
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
@ -669,9 +678,11 @@ namespace libtorrent
|
||||||
|
|
||||||
m_comment = torrent_file.dict_find_string_value("comment.utf-8");
|
m_comment = torrent_file.dict_find_string_value("comment.utf-8");
|
||||||
if (m_comment.empty()) m_comment = torrent_file.dict_find_string_value("comment");
|
if (m_comment.empty()) m_comment = torrent_file.dict_find_string_value("comment");
|
||||||
|
verify_encoding(m_comment);
|
||||||
|
|
||||||
m_created_by = torrent_file.dict_find_string_value("created by.utf-8");
|
m_created_by = torrent_file.dict_find_string_value("created by.utf-8");
|
||||||
if (m_created_by.empty()) m_created_by = torrent_file.dict_find_string_value("created by");
|
if (m_created_by.empty()) m_created_by = torrent_file.dict_find_string_value("created by");
|
||||||
|
verify_encoding(m_created_by);
|
||||||
|
|
||||||
lazy_entry const* info = torrent_file.dict_find_dict("info");
|
lazy_entry const* info = torrent_file.dict_find_dict("info");
|
||||||
if (info == 0)
|
if (info == 0)
|
||||||
|
|
Loading…
Reference in New Issue