Skip to content

Commit

Permalink
fix: 🐜 fix nested cdata in AdParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
carpasse committed Jan 28, 2019
1 parent c18922a commit 9b9c2d6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fixtures/vast-vpaid-inline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<InteractiveCreativeFile apiFramework="VPAID" type="text/javascript">https://test.example.com/html5.js</InteractiveCreativeFile>
<InteractiveCreativeFile apiFramework="VPAID" type="application/x-shockwave-flash">https://test.example.com/flash.swf</InteractiveCreativeFile>
</MediaFiles>
<AdParameters xmlEncoded="false"><![CDATA[AD_PARAMETERS_DATA]]></AdParameters>
<AdParameters xmlEncoded="false"><![CDATA[AD_PARAMETERS_DATA <![CDATA[nested cdata]]]]><![CDATA[>]]></AdParameters>
<Icons>
<Icon program="MOL_STATIC" width="20px" height="20px" xPosition="right" yPosition="top" duration="00:00:30" offset="00:00:05" pxratio="1">
<StaticResource>https://test.example.com/icon/staticResource</StaticResource>
Expand Down
2 changes: 1 addition & 1 deletion src/adUnit/helpers/vpaid/__tests__/initAd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('initAd', () => {
'thumbnail',
-1,
{
AdParameters: 'AD_PARAMETERS_DATA',
AdParameters: 'AD_PARAMETERS_DATA <![CDATA[nested cdata]]>',
xmlEncoded: false
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/vastSelectors/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ test('getCreativeData must return the adParameters', () => {
});

expect(getCreativeData(vastVpaidInlineXML)).toEqual({
AdParameters: 'AD_PARAMETERS_DATA',
AdParameters: 'AD_PARAMETERS_DATA <![CDATA[nested cdata]]>',
xmlEncoded: false
});
});
7 changes: 5 additions & 2 deletions src/vastSelectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,11 @@ const getAdParametersContent = (xml) => {
const paramsRegex = /<AdParameters[\s\w="]*>([\s\S]*)<\/AdParameters>/gm;
const result = paramsRegex.exec(xml);

return result && result[1].replace('<![CDATA[', '')
.replace(']]>', '')
return result && result[1].replace(/[\n\s]*<!\[CDATA\[[\n\s]*/, '')
.replace(/[\n\s]*\]\]>[\n\s]*$/, '')

// unescape nested CDATA
.replace(/\]\]\]\]><!\[CDATA\[>/, ']]>')
.trim();
};

Expand Down

0 comments on commit 9b9c2d6

Please sign in to comment.