fix LRF RLF unicode symbols in names and file paths

add vscode in gitignore
This commit is contained in:
rumanzo 2023-12-06 21:41:15 +03:00
parent 0b305dd2f9
commit ee7cb09a2e
No known key found for this signature in database
3 changed files with 51 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea .idea
.vscode
bt2qbt_v* bt2qbt_v*
vendors vendors

View File

@ -3,6 +3,11 @@ package transfer
import ( import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"io"
"regexp"
"strings"
"time"
"github.com/rumanzo/bt2qbt/internal/options" "github.com/rumanzo/bt2qbt/internal/options"
"github.com/rumanzo/bt2qbt/internal/replace" "github.com/rumanzo/bt2qbt/internal/replace"
"github.com/rumanzo/bt2qbt/pkg/fileHelpers" "github.com/rumanzo/bt2qbt/pkg/fileHelpers"
@ -12,10 +17,6 @@ import (
"github.com/rumanzo/bt2qbt/pkg/torrentStructures" "github.com/rumanzo/bt2qbt/pkg/torrentStructures"
"github.com/rumanzo/bt2qbt/pkg/utorrentStructs" "github.com/rumanzo/bt2qbt/pkg/utorrentStructs"
"github.com/zeebo/bencode" "github.com/zeebo/bencode"
"io"
"regexp"
"strings"
"time"
) )
//goland:noinspection GoNameStartsWithPackageName //goland:noinspection GoNameStartsWithPackageName
@ -276,10 +277,19 @@ func (transfer *TransferStructure) HandleSavePaths() {
var nameNormalized bool var nameNormalized bool
transfer.Fastresume.Name, nameNormalized = normalization.FullNormalize(transfer.TorrentFile.GetTorrentName()) transfer.Fastresume.Name, nameNormalized = normalization.FullNormalize(transfer.TorrentFile.GetTorrentName())
if strings.ContainsAny(transfer.Fastresume.Name, "\u200e\u200f") {
nameNormalized = true
}
lastPathName := fileHelpers.Base(helpers.HandleCesu8(transfer.ResumeItem.Path)) lastPathName := fileHelpers.Base(helpers.HandleCesu8(transfer.ResumeItem.Path))
// if FileList contain only 1 file that means it is single file torrent // if FileList contain only 1 file that means it is single file torrent
if !transfer.TorrentFile.IsSingle() { if !transfer.TorrentFile.IsSingle() {
fileList, filesNormalized := transfer.TorrentFile.GetFileList() fileList, filesNormalized := transfer.TorrentFile.GetFileList()
for _, file := range fileList {
if strings.ContainsAny(file, "\u200e\u200f") {
filesNormalized = true
}
}
if lastPathName == transfer.Fastresume.Name && !filesNormalized && !nameNormalized { if lastPathName == transfer.Fastresume.Name && !filesNormalized && !nameNormalized {
transfer.Fastresume.QBtContentLayout = "Original" transfer.Fastresume.QBtContentLayout = "Original"

View File

@ -1,6 +1,10 @@
package transfer package transfer
import ( import (
"fmt"
"reflect"
"testing"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/r3labs/diff/v2" "github.com/r3labs/diff/v2"
_ "github.com/r3labs/diff/v2" _ "github.com/r3labs/diff/v2"
@ -8,8 +12,6 @@ import (
"github.com/rumanzo/bt2qbt/pkg/qBittorrentStructures" "github.com/rumanzo/bt2qbt/pkg/qBittorrentStructures"
"github.com/rumanzo/bt2qbt/pkg/torrentStructures" "github.com/rumanzo/bt2qbt/pkg/torrentStructures"
"github.com/rumanzo/bt2qbt/pkg/utorrentStructs" "github.com/rumanzo/bt2qbt/pkg/utorrentStructs"
"reflect"
"testing"
) )
func TestTransferStructure_HandleSavePaths(t *testing.T) { func TestTransferStructure_HandleSavePaths(t *testing.T) {
@ -1684,6 +1686,37 @@ func TestTransferStructure_HandleSavePaths(t *testing.T) {
}, },
}, },
}, },
{
name: "047 Test torrent with multi file torrent with transfer to NoSubfolder RLF LRF symbols in torrent name and files",
newTransferStructure: &TransferStructure{
Fastresume: &qBittorrentStructures.QBittorrentFastresume{},
ResumeItem: &utorrentStructs.ResumeItem{
Path: "D:\\test files \u200e\u200f",
},
TorrentFile: &torrentStructures.Torrent{
Info: &torrentStructures.TorrentInfo{
Name: "test files \u200e\u200f",
Files: []*torrentStructures.TorrentFile{
&torrentStructures.TorrentFile{Path: []string{"file_with_emoji \u200e\u200f\xed\xa0\xbc\xed\xb6\x95.txt"}},
&torrentStructures.TorrentFile{Path: []string{"testdir_with_emoji_and_space \u200e\u200f\xed\xa0\xbc\xed\xb6\x95 ", "file_with/slash.txt"}},
},
},
},
Opts: &options.Opts{PathSeparator: `\`},
},
expected: &TransferStructure{
Fastresume: &qBittorrentStructures.QBittorrentFastresume{
QbtSavePath: "D:/test files \u200e\u200f",
SavePath: "D:\\test files \u200e\u200f",
Name: "test files \u200e\u200f",
QBtContentLayout: `NoSubfolder`,
MappedFiles: []string{
"file_with_emoji \u200e\u200f\xf0\x9f\x86\x95.txt",
"testdir_with_emoji_and_space \u200e\u200f\xf0\x9f\x86\x95_\\file_with_slash.txt",
},
},
},
},
} }
for _, testCase := range cases { for _, testCase := range cases {
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
@ -1704,6 +1737,7 @@ func TestTransferStructure_HandleSavePaths(t *testing.T) {
t.Fatalf("Unexpected error: opts isn't equal:\nGot: %#v\nExpect %#v\nDiff: %v\n", testCase.newTransferStructure.Fastresume, testCase.expected.Fastresume, spew.Sdump(changes)) t.Fatalf("Unexpected error: opts isn't equal:\nGot: %#v\nExpect %#v\nDiff: %v\n", testCase.newTransferStructure.Fastresume, testCase.expected.Fastresume, spew.Sdump(changes))
} else if equal && testCase.mustFail { } else if equal && testCase.mustFail {
t.Fatalf("Unexpected error: structures are equal, but they shouldn't\nGot: %v\n", spew.Sdump(testCase.newTransferStructure.Fastresume)) t.Fatalf("Unexpected error: structures are equal, but they shouldn't\nGot: %v\n", spew.Sdump(testCase.newTransferStructure.Fastresume))
fmt.Print("\u200e")
} }
}) })
} }