Skip to content

Commit

Permalink
fix LRF RLF unicode symbols in names and file paths
Browse files Browse the repository at this point in the history
add vscode in gitignore
  • Loading branch information
rumanzo committed Dec 6, 2023
1 parent 0b305dd commit ee7cb09
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
bt2qbt_v*
vendors
18 changes: 14 additions & 4 deletions internal/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package transfer
import (
"crypto/sha1"
"encoding/hex"
"io"
"regexp"
"strings"
"time"

"github.com/rumanzo/bt2qbt/internal/options"
"github.com/rumanzo/bt2qbt/internal/replace"
"github.com/rumanzo/bt2qbt/pkg/fileHelpers"
Expand All @@ -12,10 +17,6 @@ import (
"github.com/rumanzo/bt2qbt/pkg/torrentStructures"
"github.com/rumanzo/bt2qbt/pkg/utorrentStructs"
"github.com/zeebo/bencode"
"io"
"regexp"
"strings"
"time"
)

//goland:noinspection GoNameStartsWithPackageName
Expand Down Expand Up @@ -276,10 +277,19 @@ func (transfer *TransferStructure) HandleSavePaths() {
var nameNormalized bool
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))
// if FileList contain only 1 file that means it is single file torrent
if !transfer.TorrentFile.IsSingle() {
fileList, filesNormalized := transfer.TorrentFile.GetFileList()
for _, file := range fileList {
if strings.ContainsAny(file, "\u200e\u200f") {
filesNormalized = true
}
}

if lastPathName == transfer.Fastresume.Name && !filesNormalized && !nameNormalized {
transfer.Fastresume.QBtContentLayout = "Original"
Expand Down
38 changes: 36 additions & 2 deletions internal/transfer/transfer_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package transfer

import (
"fmt"
"reflect"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/r3labs/diff/v2"
_ "github.com/r3labs/diff/v2"
"github.com/rumanzo/bt2qbt/internal/options"
"github.com/rumanzo/bt2qbt/pkg/qBittorrentStructures"
"github.com/rumanzo/bt2qbt/pkg/torrentStructures"
"github.com/rumanzo/bt2qbt/pkg/utorrentStructs"
"reflect"
"testing"
)

func TestTransferStructure_HandleSavePaths(t *testing.T) {
Expand Down Expand Up @@ -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 {
t.Run(testCase.name, func(t *testing.T) {
Expand All @@ -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))
} else if equal && testCase.mustFail {
t.Fatalf("Unexpected error: structures are equal, but they shouldn't\nGot: %v\n", spew.Sdump(testCase.newTransferStructure.Fastresume))
fmt.Print("\u200e")
}
})
}
Expand Down

0 comments on commit ee7cb09

Please sign in to comment.