don't replace invalid path characters in non-path strings

This commit is contained in:
Arvid Norberg
2009-11-13 02:50:07 +00:00
parent 74f235cd2e
commit 8fdeeb0497
2 changed files with 5 additions and 5 deletions

View File

@@ -90,7 +90,7 @@ namespace libtorrent
// fixes invalid UTF-8 sequences and // fixes invalid UTF-8 sequences and
// replaces characters that are invalid // replaces characters that are invalid
// in paths // in paths
bool verify_encoding(std::string& target) bool verify_encoding(std::string& target, bool fix_paths = false)
{ {
std::string tmp_path; std::string tmp_path;
bool valid_encoding = true; bool valid_encoding = true;
@@ -101,7 +101,7 @@ namespace libtorrent
if ((*i & 0x80) == 0) if ((*i & 0x80) == 0)
{ {
// replace invalid characters with '.' // replace invalid characters with '.'
if (valid_path_character(*i)) if (!fix_paths || valid_path_character(*i))
{ {
tmp_path += *i; tmp_path += *i;
} }
@@ -184,7 +184,7 @@ namespace libtorrent
void verify_encoding(file_entry& target) void verify_encoding(file_entry& target)
{ {
std::string p = target.path; std::string p = target.path;
if (!verify_encoding(p)) target.path = p; if (!verify_encoding(p, true)) target.path = p;
} }
// TODO: should this take a char const*? // TODO: should this take a char const*?
@@ -660,7 +660,7 @@ namespace libtorrent
} }
// correct utf-8 encoding errors // correct utf-8 encoding errors
verify_encoding(name); verify_encoding(name, true);
// extract file list // extract file list
lazy_entry const* i = info.dict_find_list("files"); lazy_entry const* i = info.dict_find_list("files");

View File

@@ -358,7 +358,7 @@ struct parse_state
namespace libtorrent namespace libtorrent
{ {
// defined in torrent_info.cpp // defined in torrent_info.cpp
bool verify_encoding(std::string& target); bool verify_encoding(std::string& target, bool path = true);
} }
void find_control_url(int type, char const* string, parse_state& state); void find_control_url(int type, char const* string, parse_state& state);