Skip to content

Commit

Permalink
Merge pull request MailOnline#202 from Fetz/master
Browse files Browse the repository at this point in the history
Will fix issue MailOnline#198
  • Loading branch information
carpasse committed May 11, 2016
2 parents 8b50e6a + bc019d8 commit 4d8d1b1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/scripts/ads/vast/Linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Linear(linearJTree) {
if(linearJTree.adParameters) {
this.adParameters = xml.keyValue(linearJTree.adParameters);

if(xml.attr(linearJTree.adParameters, 'xmlEncoded')){
if(xml.attr(linearJTree.adParameters, 'xmlEncoded')) {
this.adParameters = xml.decode(this.adParameters);
}
}
Expand Down Expand Up @@ -74,4 +74,4 @@ Linear.prototype.isSupported = function () {
return false;
};

module.exports = Linear;
module.exports = Linear;
4 changes: 2 additions & 2 deletions src/scripts/utils/utilityFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function isArrayLike(obj) {
typeof length === 'number' && length > 0 && (length - 1) in obj;
}

function isString(str){
function isString(str) {
return typeof str === 'string';
}

Expand Down Expand Up @@ -324,4 +324,4 @@ var utilities = {
isAndroid: isAndroid
};

module.exports = utilities;
module.exports = utilities;
6 changes: 5 additions & 1 deletion src/scripts/utils/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ xml.attr = function getAttrValue(xmlObj, attr) {
};

xml.encode = function encodeXML(str) {
if (!utilities.isString(str)) return undefined;

return str.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
Expand All @@ -136,11 +138,13 @@ xml.encode = function encodeXML(str) {
};

xml.decode = function decodeXML(str) {
if (!utilities.isString(str)) return undefined;

return str.replace(/&apos;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&gt;/g, '>')
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&');
};

module.exports = xml;
module.exports = xml;
15 changes: 14 additions & 1 deletion test/ads/vast/Linear.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ describe("Linear", function () {
});

describe("AdParameters", function () {
it("must handle when no parameters is passed", function () {

[true, false].map(function(xmlEncoded) {
return '<AdParameters xmlEncoded="' + xmlEncoded + '"><![CDATA[ ]]></AdParameters>';
}).forEach(function (adParametersString) {

var linearXML = '<Linear skipoffset="10%">' + adParametersString + '</Linear>';
assert.doesNotThrow(function () {
return new Linear(xml.toJXONTree(linearXML));
});
});
});

it("must be added to the linear", function () {
var encodedAdParameters = xml.encode('<some>data</some>');

Expand Down Expand Up @@ -205,4 +218,4 @@ describe("Linear", function () {
assert.isFalse(linear.isSupported());
});
});
});
});
12 changes: 11 additions & 1 deletion test/utils/xml/xml.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,24 @@ describe("xml", function () {
});

describe("encode", function(){
it("must return undefined when is not passed a string", function() {
assert.isUndefined(xml.encode());
assert.isUndefined(xml.encode({}));
});

it("must encode &, \", ', < and >", function(){
assert.equal(xml.encode("<br/> \"'"), '&lt;br/&gt; &quot;&apos;' );
});
});

describe("decode", function(){
it("must return undefined when is not passed a string", function() {
assert.isUndefined(xml.decode());
assert.isUndefined(xml.decode({}));
});

it("must edcode a previously encoded xml", function(){
assert.equal(xml.decode('&lt;br/&gt; &quot;&apos;'), "<br/> \"'");
});
});
});
});

0 comments on commit 4d8d1b1

Please sign in to comment.