use file path and url path scape
This commit is contained in:
parent
a47fe981a2
commit
1c32fecd2d
16
CHANGELOG.md
16
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
|
||||
- Unittests
|
||||
|
||||
## [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
|
||||
|
||||
|
@ -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 (
|
||||
|
@ -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 = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<published>2020-05-25T00:00:00+00:00</published>
|
||||
<updated>2020-05-25T00:00:00+00:00</updated>
|
||||
</entry>
|
||||
<entry>
|
||||
<title>new folder</title>
|
||||
<id>/new folder</id>
|
||||
<link rel="subsection" href="/new%20folder" type="application/atom+xml;profile=opds-catalog;kind=acquisition" title="new folder"></link>
|
||||
<published>2020-05-25T00:00:00+00:00</published>
|
||||
<updated>2020-05-25T00:00:00+00:00</updated>
|
||||
</entry>
|
||||
</feed>`
|
||||
|
||||
var acquisitionFeed = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -91,6 +99,20 @@ var acquisitionFeed = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<author>
|
||||
<name></name>
|
||||
</author>
|
||||
<entry>
|
||||
<title>mybook copy.epub</title>
|
||||
<id>/mybookmybook copy.epub</id>
|
||||
<link rel="http://opds-spec.org/acquisition" href="/mybook/mybook%20copy.epub" type="application/epub+zip" title="mybook copy.epub"></link>
|
||||
<published>2020-05-25T00:00:00+00:00</published>
|
||||
<updated>2020-05-25T00:00:00+00:00</updated>
|
||||
</entry>
|
||||
<entry>
|
||||
<title>mybook copy.txt</title>
|
||||
<id>/mybookmybook copy.txt</id>
|
||||
<link rel="http://opds-spec.org/acquisition" href="/mybook/mybook%20copy.txt" type="text/plain; charset=utf-8" title="mybook copy.txt"></link>
|
||||
<published>2020-05-25T00:00:00+00:00</published>
|
||||
<updated>2020-05-25T00:00:00+00:00</updated>
|
||||
</entry>
|
||||
<entry>
|
||||
<title>mybook.epub</title>
|
||||
<id>/mybookmybook.epub</id>
|
||||
|
BIN
internal/service/testdata/mybook/mybook copy.epub
vendored
Normal file
BIN
internal/service/testdata/mybook/mybook copy.epub
vendored
Normal file
Binary file not shown.
1
internal/service/testdata/mybook/mybook copy.txt
vendored
Normal file
1
internal/service/testdata/mybook/mybook copy.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
Fixture
|
1
internal/service/testdata/new folder/mybook.txt
vendored
Normal file
1
internal/service/testdata/new folder/mybook.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
Fixture
|
Loading…
Reference in New Issue
Block a user