feat: restore support for nonstandard `path.utf-8` (#3454)

This commit is contained in:
Colin B 2023-03-13 11:58:59 -07:00 committed by GitHub
parent 67f6dee04a
commit 59a157ebde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 11 deletions

View File

@ -171,6 +171,11 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
file_subpath_.clear();
file_length_ = 0;
}
else if (pathStartsWith(InfoKey, FilesKey, ""sv, PathUtf8Key))
{
// torrent has a utf8 path, drop the other one due to probable non-utf8 encoding
file_subpath_.clear();
}
return BasicHandler::StartArray(context);
}
@ -251,7 +256,8 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
pathStartsWith(InfoKey, FileDurationKey) || //
pathStartsWith(InfoKey, FileMediaKey) || //
pathStartsWith(InfoKey, ProfilesKey) || //
pathStartsWith(LibtorrentResumeKey))
pathStartsWith(LibtorrentResumeKey) || //
pathStartsWith(NodesKey))
{
// unused by Transmission
}
@ -292,7 +298,7 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
}
else if (state_ == State::Files)
{
if (curdepth > 1 && key(curdepth - 1) == PathKey)
if (curdepth > 1 && (key(curdepth - 1) == PathKey || key(curdepth - 1) == PathUtf8Key))
{
if (!std::empty(file_subpath_))
{
@ -312,8 +318,7 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
pathIs(InfoKey, FilesKey, ""sv, Md5Key) || //
pathIs(InfoKey, FilesKey, ""sv, Md5sumKey) || //
pathIs(InfoKey, FilesKey, ""sv, MtimeKey) || // (why a string?)
pathIs(InfoKey, FilesKey, ""sv, Sha1Key) || //
pathStartsWith(InfoKey, FilesKey, ""sv, PathUtf8Key))
pathIs(InfoKey, FilesKey, ""sv, Sha1Key))
{
// unused by Transmission
}
@ -330,7 +335,10 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
{
tm_.creator_ = tr_strv_replace_invalid(value);
}
else if (pathIs(SourceKey) || pathIs(InfoKey, SourceKey) || pathIs(PublisherKey) || pathIs(InfoKey, PublisherKey))
else if (
pathIs(SourceKey) || pathIs(InfoKey, SourceKey) || //
pathIs(PublisherKey) || pathIs(InfoKey, PublisherKey) || //
pathIs(PublisherUtf8Key) || pathIs(InfoKey, PublisherUtf8Key))
{
// “publisher” is rare, but used by BitComet and appears
// to have the same use as the 'source' key
@ -404,12 +412,14 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
pathIs(InfoKey, EntropyKey) || //
pathIs(InfoKey, Md5sumKey) || //
pathIs(InfoKey, PublisherUrlKey) || //
pathIs(InfoKey, PublisherUrlUtf8Key) || //
pathIs(InfoKey, Sha1Key) || //
pathIs(InfoKey, UniqueKey) || //
pathIs(InfoKey, XCrossSeedKey) || //
pathIs(LocaleKey) || //
pathIs(LogCallbackKey) || //
pathIs(PublisherUrlKey) || //
pathIs(PublisherUrlUtf8Key) || //
pathIs(TitleKey) || //
pathStartsWith(AzureusPrivatePropertiesKey) || //
pathStartsWith(AzureusPropertiesKey) || //
@ -417,7 +427,8 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDe
pathStartsWith(InfoKey, FileDurationKey) || //
pathStartsWith(InfoKey, ProfilesKey) || //
pathStartsWith(LibtorrentResumeKey) || //
pathStartsWith(MagnetInfoKey))
pathStartsWith(MagnetInfoKey) || //
pathStartsWith(NodesKey))
{
// unused by Transmission
}
@ -594,6 +605,7 @@ private:
static constexpr std::string_view MtimeKey = "mtime"sv;
static constexpr std::string_view NameKey = "name"sv;
static constexpr std::string_view NameUtf8Key = "name.utf-8"sv;
static constexpr std::string_view NodesKey = "nodes"sv;
static constexpr std::string_view PathKey = "path"sv;
static constexpr std::string_view PathUtf8Key = "path.utf-8"sv;
static constexpr std::string_view PieceLayersKey = "piece layers"sv;
@ -603,7 +615,9 @@ private:
static constexpr std::string_view PrivateKey = "private"sv;
static constexpr std::string_view ProfilesKey = "profiles"sv;
static constexpr std::string_view PublisherKey = "publisher"sv;
static constexpr std::string_view PublisherUtf8Key = "publisher.utf-8"sv;
static constexpr std::string_view PublisherUrlKey = "publisher-url"sv;
static constexpr std::string_view PublisherUrlUtf8Key = "publisher-url.utf-8"sv;
static constexpr std::string_view Sha1Key = "sha1"sv;
static constexpr std::string_view SourceKey = "source"sv;
static constexpr std::string_view TitleKey = "title"sv;

View File

@ -11,8 +11,9 @@ function(AddShowTest name file_basename)
endfunction()
# disabled AddShowTest(transmission-show-bittorrent-v2 bittorrent-v2-test)
addshowtest(transmission-show-bittorrent-v2-hybrid-test bittorrent-v2-hybrid-test)
addshowtest(transmission-show-inner-sanctum Inner_Sanctum_movie_archive)
addshowtest(transmission-show-thor Thor_and_the_Amazon_Women.avi)
addshowtest(transmission-show-ubuntu ubuntu-20.04.3-desktop-amd64.iso)
addshowtest(transmission-show-ubuntu-hybrid hybrid-single-ubuntu-20.04.3-desktop-amd64.iso)
AddShowTest(transmission-show-bittorrent-v2-hybrid-test bittorrent-v2-hybrid-test)
AddShowTest(transmission-show-inner-sanctum Inner_Sanctum_movie_archive)
AddShowTest(transmission-show-thor Thor_and_the_Amazon_Women.avi)
AddShowTest(transmission-show-ubuntu ubuntu-20.04.3-desktop-amd64.iso)
AddShowTest(transmission-show-ubuntu-hybrid hybrid-single-ubuntu-20.04.3-desktop-amd64.iso)
AddShowTest(transmission-show-bitcomet-path.utf8 bitcomet.utf-8.special)

View File

@ -0,0 +1,26 @@
Name: modified test-utf8
File: assets/bitcomet.utf-8.special.torrent
GENERAL
Name: modified test-utf8
Hash v1: 52bb66ab192b38cad7ce20fb8ee2dfe1d870bea8
Created by: Hand with love
Created on: Sat Jul 16 21:13:04 2022
Source: 私たちの世界
Piece Count: 1
Piece Size: 1.00 MiB
Total Size: 0.01 kB
Privacy: Public torrent
TRACKERS
Tier #1
http://fake.example.com:7070/announce
FILES
modified test-utf8/別の世界f1.txt (0.01 kB)
modified test-utf8/別の世界f2.txt (0.01 kB)

Binary file not shown.

View File

@ -14,9 +14,13 @@ else()
message(STATUS " output_file ${output_file}")
message(STATUS " reference_file ${reference_file}")
# We want UTF-8
set(ENV{LC_ALL} "en_US.UTF-8")
# The app's output includes timestamps, so fake our TZ to ensure
# the test doesn't depend on the physical TZ of the test machine
set(ENV{TZ} "UTC")
execute_process(
COMMAND ${transmission_show} ${torrent_file}
OUTPUT_FILE ${output_file})