[PATCH] msgstore_fs: Escape filenames with url.PathEscape
Export this patch
Previously, channels with characters like '/' would just get replaced
with '-'. This caused soju+gamja to act very weirdly, like showing
two channels instead of one.
Note: This is my first time contributing to a Go project, please
review this carefully. Seems to work fine for me while testing with
chathistorysync and senpai.
Closes: https://todo.sr.ht/~emersion/soju/208
Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
---
msgstore/fs.go | 9 +++++++ --
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/msgstore/fs.go b/msgstore/fs.go
index 00f0e00..a6cfa67 100644
--- a/msgstore/fs.go
+++ b/msgstore/fs.go
@@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
+ "net/url"
"os"
"path/filepath"
"sort"
@@ -30,7 +31,7 @@ func EscapeFilename(unsafe string) (safe string) {
} else if unsafe == ".." {
return "--"
} else {
- return strings.NewReplacer("/", "-", "\\", "-").Replace(unsafe)
+ return url.PathEscape(unsafe)
}
}
@@ -492,8 +493,12 @@ func (ms *fsMessageStore) ListTargets(ctx context.Context, network *database.Net
continue
}
+ targetName, err := url.PathUnescape(target)
+ if err != nil {
+ return nil, err
+ }
targets = append(targets, ChatHistoryTarget{
- Name: target,
+ Name: targetName,
LatestMessage: t,
})
--
2.40.0
Probably better to make a separate EscapeFilename function for
channels, and then unescape the channel name for CHATHISTORY like I
currently do.
This will escape the whole path which won't work with for ex.
"/var/lib/#/soju/fs_store".
Will send an update later today.
I've been holding off this patch because it behaves differently than
ZNC, which we inherit the log format from. ZNC escapes with "-" as well.