diff --git a/CHANGELOG.md b/CHANGELOG.md
index f2d115a..59e7a0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,30 +4,34 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [0.0.10] - 2021-05-30
+## [0.0.11] - 2021-06-05
+### Changed
+- return to filepath as the best way to handle paths for different platforms.
+
+## [0.0.10] - 2021-05-06
### Added
- Unittests
### Changed
- structure of the project changed but public endpoint remains backward compatible.
-## [0.0.9] - 2021-05-30
+## [0.0.9] - 2021-05-06
### Changed
- using actions in github for building binaries only when tagging.
-## [0.0.8] - 2021-05-30
+## [0.0.8] - 2021-05-06
### Changed
- using actions in github for building binaries only when tagging.
-## [0.0.7] - 2021-05-30
+## [0.0.7] - 2021-05-06
### Changed
- using actions in github for testing
-## [0.0.6] - 2021-05-30
+## [0.0.6] - 2021-05-06
### Changed
- using actions in github for testing
-## [0.0.5] - 2020-05-30
+## [0.0.5] - 2020-05-06
### removed
- usage of filepath package
diff --git a/internal/service/service.go b/internal/service/service.go
index 4139960..54c2c9b 100644
--- a/internal/service/service.go
+++ b/internal/service/service.go
@@ -10,8 +10,8 @@ import (
"log"
"mime"
"net/http"
+ "net/url"
"os"
- "path"
"path/filepath"
"time"
@@ -37,7 +37,7 @@ type OPDS struct {
var TimeNowFunc = timeNow
func (s OPDS) Handler(w http.ResponseWriter, req *http.Request) error {
- fPath := path.Join(s.DirRoot, req.URL.Path)
+ fPath := filepath.Join(s.DirRoot, req.URL.Path)
log.Printf("fPath:'%s'", fPath)
@@ -84,7 +84,7 @@ func (s OPDS) makeFeed(dirpath string, req *http.Request) atom.Feed {
fis, _ := ioutil.ReadDir(dirpath)
for _, fi := range fis {
- pathType := getPathType(path.Join(dirpath, fi.Name()))
+ pathType := getPathType(filepath.Join(dirpath, fi.Name()))
feedBuilder = feedBuilder.
AddEntry(opds.EntryBuilder.
ID(req.URL.Path + fi.Name()).
@@ -124,7 +124,7 @@ func getType(name string, pathType int) string {
}
func getHref(req *http.Request, name string) string {
- return path.Join(req.URL.RequestURI(), name)
+ return filepath.Join(req.URL.RequestURI(), url.PathEscape(name))
}
const (
diff --git a/internal/service/service_test.go b/internal/service/service_test.go
index e070cad..33d321b 100644
--- a/internal/service/service_test.go
+++ b/internal/service/service_test.go
@@ -27,6 +27,7 @@ func TestHandler(t *testing.T) {
"feed (dir of folders )": {input: "/", want: feed, WantedContentType: "application/xml"},
"acquisitionFeed(dir of files)": {input: "/mybook", want: acquisitionFeed, WantedContentType: "application/xml"},
"servingAFile": {input: "/mybook/mybook.txt", want: "Fixture", WantedContentType: "text/plain; charset=utf-8"},
+ "serving file with spaces": {input: "/mybook/mybook%20copy.txt", want: "Fixture", WantedContentType: "text/plain; charset=utf-8"},
}
for name, tc := range tests {
@@ -80,6 +81,13 @@ var feed = `
2020-05-25T00:00:00+00:00
2020-05-25T00:00:00+00:00
+
+ new folder
+ /new folder
+
+ 2020-05-25T00:00:00+00:00
+ 2020-05-25T00:00:00+00:00
+
`
var acquisitionFeed = `
@@ -91,6 +99,20 @@ var acquisitionFeed = `
+
+ mybook copy.epub
+ /mybookmybook copy.epub
+
+ 2020-05-25T00:00:00+00:00
+ 2020-05-25T00:00:00+00:00
+
+
+ mybook copy.txt
+ /mybookmybook copy.txt
+
+ 2020-05-25T00:00:00+00:00
+ 2020-05-25T00:00:00+00:00
+
mybook.epub
/mybookmybook.epub
diff --git a/internal/service/testdata/mybook/mybook copy.epub b/internal/service/testdata/mybook/mybook copy.epub
new file mode 100644
index 0000000..b675c76
Binary files /dev/null and b/internal/service/testdata/mybook/mybook copy.epub differ
diff --git a/internal/service/testdata/mybook/mybook copy.txt b/internal/service/testdata/mybook/mybook copy.txt
new file mode 100644
index 0000000..fdfaaa1
--- /dev/null
+++ b/internal/service/testdata/mybook/mybook copy.txt
@@ -0,0 +1 @@
+Fixture
\ No newline at end of file
diff --git a/internal/service/testdata/new folder/mybook.txt b/internal/service/testdata/new folder/mybook.txt
new file mode 100644
index 0000000..fdfaaa1
--- /dev/null
+++ b/internal/service/testdata/new folder/mybook.txt
@@ -0,0 +1 @@
+Fixture
\ No newline at end of file