Merge pull request #58 from webp-sh/url_decode_fix

url with url-encoded character fix
This commit is contained in:
Benny 2020-11-25 11:34:01 +08:00 committed by GitHub
commit 1881ae83cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 20 deletions

View File

@ -22,6 +22,7 @@ func TestWebpEncoder(t *testing.T) {
// test error
err := webpEncoder("./pics/empty.jpg", webp, 80, true, nil)
assert.NotNil(t, err)
_ = os.Remove(webp)
}
func TestNonImage(t *testing.T) {
@ -29,14 +30,10 @@ func TestNonImage(t *testing.T) {
// test error
var err = webpEncoder("./pics/empty.jpg", webp, 80, true, nil)
assert.NotNil(t, err)
_ = os.Remove(webp)
}
func TestWriteFail(t *testing.T) {
// test permission denied
var webp = "/123.webp"
var err = webpEncoder("./pics/png.jpg", webp, 80, true, nil)
assert.NotNil(t, err)
}
func walker() []string {
var list []string
_ = filepath.Walk("./pics", func(path string, info os.FileInfo, err error) error {

View File

@ -116,7 +116,7 @@ func TestChanErr(t *testing.T) {
}
func TestGetRemoteImageInfo(t *testing.T) {
url := "http://github.com/favicon.ico"
url := "https://github.com/favicon.ico"
statusCode, etag := getRemoteImageInfo(url)
assert.NotEqual(t, "", etag)
assert.Equal(t, statusCode, http.StatusOK)

BIN
pics/太神啦.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

View File

@ -16,7 +16,7 @@ func TestPrefetchImages(t *testing.T) {
_ = os.Mkdir(fp, 0755)
prefetchImages("./pics", "./prefetch", "80")
count := fileCount("./prefetch")
assert.Equal(t, 6, count)
assert.Equal(t, 7, count)
_ = os.RemoveAll(fp)
// concurrency
@ -24,6 +24,6 @@ func TestPrefetchImages(t *testing.T) {
_ = os.Mkdir(fp, 0755)
prefetchImages("./pics", "./prefetch", "80")
count = fileCount("./prefetch")
assert.Equal(t, 4, count)
assert.Equal(t, 5, count)
_ = os.RemoveAll(fp)
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/gofiber/fiber/v2"
log "github.com/sirupsen/logrus"
"net/url"
"os"
"path"
"path/filepath"
@ -14,7 +15,7 @@ import (
func convert(c *fiber.Ctx) error {
//basic vars
var reqURI = c.Path() // /mypic/123.jpg
var reqURI, _ = url.QueryUnescape(c.Path()) // /mypic/123.jpg
var rawImageAbs = path.Join(config.ImgPath, reqURI) // /home/xxx/mypic/123.jpg
var imgFilename = path.Base(reqURI) // pure filename, 123.jpg
var finalFile string // We'll only need one c.sendFile()

View File

@ -21,13 +21,15 @@ var (
func TestConvert(t *testing.T) {
setupParam()
var testChromeLink = map[string]string{
"http://127.0.0.1:3333/webp_server.jpg": "image/webp",
"http://127.0.0.1:3333/webp_server.bmp": "image/webp",
"http://127.0.0.1:3333/webp_server.png": "image/webp",
"http://127.0.0.1:3333/empty.jpg": "text/plain; charset=utf-8",
"http://127.0.0.1:3333/png.jpg": "image/webp",
"http://127.0.0.1:3333/12314.jpg": "text/plain; charset=utf-8",
"http://127.0.0.1:3333/dir1/inside.jpg": "image/webp",
"http://127.0.0.1:3333/webp_server.jpg": "image/webp",
"http://127.0.0.1:3333/webp_server.bmp": "image/webp",
"http://127.0.0.1:3333/webp_server.png": "image/webp",
"http://127.0.0.1:3333/empty.jpg": "text/plain; charset=utf-8",
"http://127.0.0.1:3333/png.jpg": "image/webp",
"http://127.0.0.1:3333/12314.jpg": "text/plain; charset=utf-8",
"http://127.0.0.1:3333/dir1/inside.jpg": "image/webp",
"http://127.0.0.1:3333/%e5%a4%aa%e7%a5%9e%e5%95%a6.png": "image/webp",
"http://127.0.0.1:3333/太神啦.png": "image/webp",
}
var testSafariLink = map[string]string{
@ -119,7 +121,7 @@ func setupParam() {
func requestToServer(url string, app *fiber.App, ua string) (*http.Response, []byte) {
req := httptest.NewRequest("GET", url, nil)
req.Header.Set("User-Agent", ua)
resp, _ := app.Test(req)
resp, _ := app.Test(req, 60000)
data, _ := ioutil.ReadAll(resp.Body)
return resp, data
}

View File

@ -1,5 +1,5 @@
Name: webp-server
Version: 0.2.1
Version: 0.2.2
Release: 1%{?dist}
Summary: Go version of WebP Server. A tool that will serve your JPG/PNGs as WebP format with compression, on-the-fly.

View File

@ -28,7 +28,7 @@ var (
proxyMode bool
config Config
version = "0.2.1"
version = "0.2.2"
)
const (