Skip to content

Commit

Permalink
UOE-11484: fixing invalid vast xml for spaces in pricing node (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-viral-vala authored Nov 7, 2024
1 parent b9681b8 commit 1fb78f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions adapters/vastbidder/etree_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ func getPricingDetailsTestCases() []struct {
wantPrice: 12.05,
wantCurrency: "USD",
},
{
name: "vast_with_whitespace_cdata_pricing",
vastXML: `<VAST version="3.0"><Ad><Wrapper><Pricing> <![CDATA[ 12.05 ]]> </Pricing></Wrapper></Ad></VAST>`,
wantPrice: 12.05,
wantCurrency: "USD",
},
{
name: "vast_gt_2.x_pricing",
vastXML: `<VAST version="3.0"><Ad><Wrapper><Pricing>12.05</Pricing></Wrapper></Ad></VAST>`,
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/tracker/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func InjectPricingNodeInVAST(parent *etree.Element, price float64, model string,

func updatePricingNode(node *etree.Element, price float64, model string, currency string) {
//Update Price

node.Child = nil
node.SetText(fmt.Sprintf("%v", price))

//Update Pricing.Model
Expand Down
20 changes: 20 additions & 0 deletions modules/pubmatic/openwrap/tracker/video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,26 @@ func Test_updatePricingNode(t *testing.T) {
},
want: `<Pricing model="` + models.VideoPricingModelCPM + `" currency="` + models.VideoPricingCurrencyUSD + `"><![CDATA[1.2]]></Pricing>`,
},
{
name: "adding_space_in_price",
args: args{
doc: getXMLDocument(`<Pricing> 4.5 </Pricing>`),
price: 1.2,
model: "",
currency: "",
},
want: `<Pricing model="` + models.VideoPricingModelCPM + `" currency="` + models.VideoPricingCurrencyUSD + `"><![CDATA[1.2]]></Pricing>`,
},
{
name: "adding_space_in_price_with_cdata",
args: args{
doc: getXMLDocument(`<Pricing> <![CDATA[4.5]]> </Pricing>`),
price: 1.2,
model: "",
currency: "",
},
want: `<Pricing model="` + models.VideoPricingModelCPM + `" currency="` + models.VideoPricingCurrencyUSD + `"><![CDATA[1.2]]></Pricing>`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1fb78f7

Please sign in to comment.