Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trim on getcontents #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions common/utils/vast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ export function buildVast(current: Element, currentTag: VastElement<any>) {
) {
const currentTmp = current.elements[0];
const currentText = String(currentTmp.text || currentTmp.cdata);
currentTag.content = currentText;
currentTag.setContent(currentText);
} else {
let currentChild: VastElement<any>;
for (let i = 0; i < current.elements.length; i++) {
const currentTmp: Element = current.elements[i];
// TODO refacto attachCustomTag from real tag for better integration
// and fallback on dangerous
currentChild = currentTag.attachCustomTag(
currentTmp.name,
currentTmp.attributes as any
Expand Down
14 changes: 10 additions & 4 deletions common/vast-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ export default class VastElement<VastElementParent extends VastElement<any>> {
this.parent = parent;
this.name = name;
if (typeof contentOrAttributes === "string") {
if (hasCDATA(contentOrAttributes)) {
this.cdataThisOne = true;
}
this.content = stripCDATA(contentOrAttributes);
this.setContent(contentOrAttributes);
this.attrs = attributesIfContent || {};
} else {
this.content = null;
Expand All @@ -87,6 +84,15 @@ export default class VastElement<VastElementParent extends VastElement<any>> {
return this.and();
}

// > Set content, accept CDATA
// * setContent(content: string): void
public setContent(content: string): void {
if (hasCDATA(content)) {
this.cdataThisOne = true;
}
this.content = stripCDATA(content);
}

// > Get filtered attributes (only specs valids one will be returned)
// * getContent(): string
public getContent(): string {
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,37 @@
"@types/array-unique": "^0.3.0",
"@types/browserify": "^12.0.36",
"@types/expect-puppeteer": "^3.3.1",
"@types/fs-extra": "^5.1.0",
"@types/jest": "^24.0.12",
"@types/jest-environment-puppeteer": "^4.0.0",
"@types/fs-extra": "^7.0.0",
"@types/jest": "^24.0.13",
"@types/js-yaml": "^3.12.1",
"@types/nock": "^10.0.2",
"@types/prettier": "^1.16.3",
"@types/nock": "^10.0.3",
"@types/prettier": "^1.16.4",
"@types/puppeteer": "^1.12.4",
"@types/request": "^2.48.1",
"array-unique": "^0.3.2",
"browserify": "^16.2.3",
"codecov": "^3.4.0",
"codecov": "^3.5.0",
"depcheck": "^0.8.0",
"fs-extra": "^8.0.0",
"expect-puppeteer": "^4.1.1",
"fs-extra": "^8.0.1",
"http-server": "^0.11.1",
"husky": "^2.2.0",
"husky": "^2.4.0",
"jest": "^24.8.0",
"jest-puppeteer": "^4.1.1",
"jest-puppeteer": "^4.2.0",
"js-yaml": "^3.13.1",
"lint-staged": "^8.1.6",
"lint-staged": "^8.2.0",
"madge": "^3.4.4",
"nock": "^10.0.6",
"npm-run-all": "^4.1.5",
"prettier": "^1.17.0",
"puppeteer": "^1.15.0",
"prettier": "^1.17.1",
"puppeteer": "^1.17.0",
"rimraf": "^2.6.3",
"ts-jest": "^24.0.2",
"ts-node": "^8.1.0",
"ts-node": "^8.2.0",
"tsify": "^4.0.1",
"tslint": "^5.16.0",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.4.5"
"typescript": "^3.5.1"
},
"repository": {
"type": "github",
Expand Down
7 changes: 7 additions & 0 deletions tests/parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,11 @@ describe("VastParser", () => {
);
mock.mockRestore();
});
test("should trim spaces in CDATA fields", () => {
parser = new VastParser();
parser.addVastWithoutFetching(getFileContent("vast_with_spaces.xml"));

const clickThrough = parser.getContents(["ClickThrough"]);
expect(clickThrough).toEqual(["https://www.ogury.com/"]);
});
});
59 changes: 59 additions & 0 deletions tests/parser/vasts/vast_with_spaces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<VAST version="3.0">
<Ad>
<InLine>
<AdSystem/>
<AdTitle>
<![CDATA[ Sergej_Display_OMID_test_Video ]]>
</AdTitle>
<Description>
<![CDATA[ Sergej_Display_OMID_test_Video ]]>
</Description>
<Creatives>
<Creative>
<Linear>
<Duration>
<![CDATA[ 00:00:15 ]]>
</Duration>
<TrackingEvents/>
<VideoClicks>
<ClickThrough>
<![CDATA[ https://www.ogury.com/ ]]>
</ClickThrough>
</VideoClicks>
<MediaFiles>
<MediaFile type="application/vnd.apple.mpegurl">
<![CDATA[
https://medias.presage.io/medias/videos/92ad95b7-5b02-4706-8160-fe4fcce9aa66.mp4-transcoded/playlist.m3u8
]]>
</MediaFile>
<MediaFile type="video/mp4">
<![CDATA[
https://medias.presage.io/medias/videos/92ad95b7-5b02-4706-8160-fe4fcce9aa66.mp4-transcoded/offline.mp4
]]>
</MediaFile>
</MediaFiles>
</Linear>
</Creative>
</Creatives>
<Extensions>
<Extension type="AdVerifications">
<AdVerifications>
<Verification vendor="iabtechlab.com-omid">
<JavaScriptResource apiFramework="omid" browserOptional="true">
<![CDATA[https://s3-us-west-2.amazonaws.com/omsdk-files/compliance-js/omid-validation-verification-script-v1.js]]>
</JavaScriptResource>
<TrackingEvents>
<Tracking event="verificationNotExecuted">
<![CDATA[]]>
</Tracking>
</TrackingEvents>
<VerificationParameters>
<![CDATA["iabtechlab-ogury"]]>
</VerificationParameters>
</Verification>
</AdVerifications>
</Extension>
</Extensions>
</InLine>
</Ad>
</VAST>
Loading