Skip to content

Commit

Permalink
Avoid overriding AMP request original size with mutli-size (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlackty authored Jun 15, 2020
1 parent eb77b17 commit dd05c38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
17 changes: 10 additions & 7 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,31 +407,34 @@ func (deps *endpointDeps) overrideWithParams(httpRequest *http.Request, req *ope
}

func makeFormatReplacement(overrideWidth uint64, overrideHeight uint64, width uint64, height uint64, multisize string) []openrtb.Format {
var formats []openrtb.Format
if overrideWidth != 0 && overrideHeight != 0 {
return []openrtb.Format{{
formats = []openrtb.Format{{
W: overrideWidth,
H: overrideHeight,
}}
} else if overrideWidth != 0 && height != 0 {
return []openrtb.Format{{
formats = []openrtb.Format{{
W: overrideWidth,
H: height,
}}
} else if width != 0 && overrideHeight != 0 {
return []openrtb.Format{{
formats = []openrtb.Format{{
W: width,
H: overrideHeight,
}}
} else if parsedSizes := parseMultisize(multisize); len(parsedSizes) != 0 {
return parsedSizes
} else if width != 0 && height != 0 {
return []openrtb.Format{{
formats = []openrtb.Format{{
W: width,
H: height,
}}
}

return nil
if parsedSizes := parseMultisize(multisize); len(parsedSizes) != 0 {
formats = append(formats, parsedSizes...)
}

return formats
}

func setWidths(formats []openrtb.Format, width uint64) {
Expand Down
18 changes: 18 additions & 0 deletions endpoints/openrtb2/amp_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,24 @@ func TestMultisize(t *testing.T) {
}.execute(t)
}

func TestSizeWithMultisize(t *testing.T) {
formatOverrideSpec{
width: 20,
height: 40,
multisize: "200x50,100x60",
expect: []openrtb.Format{{
W: 20,
H: 40,
}, {
W: 200,
H: 50,
}, {
W: 100,
H: 60,
}},
}.execute(t)
}

func TestHeightOnly(t *testing.T) {
formatOverrideSpec{
height: 200,
Expand Down

0 comments on commit dd05c38

Please sign in to comment.