Skip to content
Permalink
Browse files

Fix options rewrite

  • Loading branch information...
DarthSim committed Jul 22, 2019
1 parent 5426c30 commit ee54296249fb2993c4ff00890e33abc58a38752c
Showing with 28 additions and 24 deletions.
  1. +6 −6 presets_test.go
  2. +9 −5 processing_options.go
  3. +13 −13 processing_options_test.go
@@ -19,8 +19,8 @@ func (s *PresetsTestSuite) TestParsePreset() {
require.Nil(s.T(), err)

assert.Equal(s.T(), urlOptions{
"resize": []string{"fit", "100", "200"},
"sharpen": []string{"2"},
urlOption{Name: "resize", Args: []string{"fit", "100", "200"}},
urlOption{Name: "sharpen", Args: []string{"2"}},
}, p["test"])
}

@@ -85,8 +85,8 @@ func (s *PresetsTestSuite) TestParsePresetComment() {
func (s *PresetsTestSuite) TestCheckPresets() {
p := presets{
"test": urlOptions{
"resize": []string{"fit", "100", "200"},
"sharpen": []string{"2"},
urlOption{Name: "resize", Args: []string{"fit", "100", "200"}},
urlOption{Name: "sharpen", Args: []string{"2"}},
},
}

@@ -98,8 +98,8 @@ func (s *PresetsTestSuite) TestCheckPresets() {
func (s *PresetsTestSuite) TestCheckPresetsInvalid() {
p := presets{
"test": urlOptions{
"resize": []string{"fit", "-1", "-2"},
"sharpen": []string{"2"},
urlOption{Name: "resize", Args: []string{"fit", "-1", "-2"}},
urlOption{Name: "sharpen", Args: []string{"2"}},
},
}

@@ -12,7 +12,11 @@ import (
"strings"
)

type urlOptions map[string][]string
type urlOption struct {
Name string
Args []string
}
type urlOptions []urlOption

type processingHeaders struct {
Accept string
@@ -713,8 +717,8 @@ func applyProcessingOption(po *processingOptions, name string, args []string) er
}

func applyProcessingOptions(po *processingOptions, options urlOptions) error {
for name, args := range options {
if err := applyProcessingOption(po, name, args); err != nil {
for _, opt := range options {
if err := applyProcessingOption(po, opt.Name, opt.Args); err != nil {
return err
}
}
@@ -723,7 +727,7 @@ func applyProcessingOptions(po *processingOptions, options urlOptions) error {
}

func parseURLOptions(opts []string) (urlOptions, []string) {
parsed := make(urlOptions)
parsed := make(urlOptions, 0, len(opts))
urlStart := len(opts) + 1

for i, opt := range opts {
@@ -734,7 +738,7 @@ func parseURLOptions(opts []string) (urlOptions, []string) {
break
}

parsed[args[0]] = args[1:]
parsed = append(parsed, urlOption{Name: args[0], Args: args[1:]})
}

var rest []string
@@ -335,12 +335,12 @@ func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedWatermark() {

func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedPreset() {
conf.Presets["test1"] = urlOptions{
"resizing_type": []string{"fill"},
urlOption{Name: "resizing_type", Args: []string{"fill"}},
}

conf.Presets["test2"] = urlOptions{
"blur": []string{"0.2"},
"quality": []string{"50"},
urlOption{Name: "blur", Args: []string{"0.2"}},
urlOption{Name: "quality", Args: []string{"50"}},
}

req := s.getRequest("http://example.com/unsafe/preset:test1:test2/plain/http://images.dev/lorem/ipsum.jpg")
@@ -356,9 +356,9 @@ func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedPreset() {

func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
conf.Presets["default"] = urlOptions{
"resizing_type": []string{"fill"},
"blur": []string{"0.2"},
"quality": []string{"50"},
urlOption{Name: "resizing_type", Args: []string{"fill"}},
urlOption{Name: "blur", Args: []string{"0.2"}},
urlOption{Name: "quality", Args: []string{"50"}},
}

req := s.getRequest("http://example.com/unsafe/quality:70/plain/http://images.dev/lorem/ipsum.jpg")
@@ -374,12 +374,12 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {

func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedPresetLoopDetection() {
conf.Presets["test1"] = urlOptions{
"resizing_type": []string{"fill"},
urlOption{Name: "resizing_type", Args: []string{"fill"}},
}

conf.Presets["test2"] = urlOptions{
"blur": []string{"0.2"},
"quality": []string{"50"},
urlOption{Name: "blur", Args: []string{"0.2"}},
urlOption{Name: "quality", Args: []string{"50"}},
}

req := s.getRequest("http://example.com/unsafe/preset:test1:test2:test1/plain/http://images.dev/lorem/ipsum.jpg")
@@ -553,10 +553,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathSignedInvalid() {
func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
conf.OnlyPresets = true
conf.Presets["test1"] = urlOptions{
"blur": []string{"0.2"},
urlOption{Name: "blur", Args: []string{"0.2"}},
}
conf.Presets["test2"] = urlOptions{
"quality": []string{"50"},
urlOption{Name: "quality", Args: []string{"50"}},
}

req := s.getRequest("http://example.com/unsafe/test1:test2/plain/http://images.dev/lorem/ipsum.jpg")
@@ -573,10 +573,10 @@ func (s *ProcessingOptionsTestSuite) TestParsePathOnlyPresets() {
func (s *ProcessingOptionsTestSuite) TestParseBase64URLOnlyPresets() {
conf.OnlyPresets = true
conf.Presets["test1"] = urlOptions{
"blur": []string{"0.2"},
urlOption{Name: "blur", Args: []string{"0.2"}},
}
conf.Presets["test2"] = urlOptions{
"quality": []string{"50"},
urlOption{Name: "quality", Args: []string{"50"}},
}

imageURL := "http://images.dev/lorem/ipsum.jpg?param=value"

0 comments on commit ee54296

Please sign in to comment.
You can’t perform that action at this time.