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/Handle duplicate VASTAdTagURI in AdPod #452

Merged
merged 4 commits into from
Aug 23, 2023
Merged
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
100 changes: 52 additions & 48 deletions spec/vast_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,32 @@ describe('VASTParser', () => {
});
});

it('applies url filters and saves url in parentURLs', () => {
it('applies url filters', (done) => {
VastParser.URLTemplateFilters = [(url) => url.replace('foo', 'bar')];

return VastParser.fetchVAST('www.foo.foo').finally(() => {
expect(VastParser.parentURLs).toEqual(['www.bar.foo']);
const urlHandlerSpy = jest.spyOn(VastParser.urlHandler, 'get');

VastParser.fetchVAST('www.foo.foo').then(() => {
expect(urlHandlerSpy).toHaveBeenCalledWith(
'www.bar.foo',
expect.anything(),
expect.anything()
);
done();
});
});

it('emits VAST-resolving and VAST-resolved events', () => {
it('emits VAST-resolving and VAST-resolved events with filtered url', () => {
VastParser.URLTemplateFilters = [(url) => url.replace('foo', 'bar')];

return VastParser.fetchVAST(
'www.foo.foo',
2,
'www.original.foo',
ad
).finally(() => {
expect(VastParser.emit).toHaveBeenNthCalledWith(1, 'VAST-resolving', {
url: 'www.foo.foo',
url: 'www.bar.foo',
previousUrl: 'www.original.foo',
wrapperDepth: 2,
maxWrapperDepth: 8,
Expand All @@ -105,7 +114,7 @@ describe('VASTParser', () => {
});

expect(VastParser.emit).toHaveBeenNthCalledWith(2, 'VAST-resolved', {
url: 'www.foo.foo',
url: 'www.bar.foo',
previousUrl: 'www.original.foo',
wrapperDepth: 2,
error: null,
Expand Down Expand Up @@ -142,50 +151,47 @@ describe('VASTParser', () => {
});
});

it('applies url filters and saves url in parentURLs', () => {
it('applies url filters', () => {
VastParser.URLTemplateFilters = [(url) => url.replace('foo', 'bar')];

return VastParser.fetchVAST('www.foo.foo')
.then(() => {
expect(true).toBeFalsy();
})
.catch(() => {
expect(VastParser.parentURLs).toEqual(['www.bar.foo']);
});
const urlHandlerSpy = jest.spyOn(VastParser.urlHandler, 'get');

return VastParser.fetchVAST('www.foo.foo').catch(() => {
expect(urlHandlerSpy).toHaveBeenCalledWith(
'www.bar.foo',
expect.anything(),
expect.anything()
);
});
});

it('emits VAST-resolving and VAST-resolved events', () => {
return VastParser.fetchVAST('www.foo.foo', 2, 'www.original.foo', ad)
.then(() => {
expect(true).toBeFalsy();
})
.catch(() => {
expect(VastParser.emit).toHaveBeenNthCalledWith(
1,
'VAST-resolving',
{
url: 'www.foo.foo',
previousUrl: 'www.original.foo',
wrapperDepth: 2,
maxWrapperDepth: 8,
timeout: 120000,
wrapperAd: ad,
}
);

expect(VastParser.emit).toHaveBeenNthCalledWith(
2,
'VAST-resolved',
{
url: 'www.foo.foo',
previousUrl: 'www.original.foo',
wrapperDepth: 2,
error: new Error('timeout'),
duration: expect.any(Number),
statusCode: 408,
}
);
it('emits VAST-resolving and VAST-resolved events with filtered url', () => {
VastParser.URLTemplateFilters = [(url) => url.replace('foo', 'bar')];

return VastParser.fetchVAST(
'www.foo.foo',
2,
'www.original.foo',
ad
).catch(() => {
expect(VastParser.emit).toHaveBeenNthCalledWith(1, 'VAST-resolving', {
url: 'www.bar.foo',
previousUrl: 'www.original.foo',
wrapperDepth: 2,
maxWrapperDepth: 8,
timeout: 120000,
wrapperAd: ad,
});

expect(VastParser.emit).toHaveBeenNthCalledWith(2, 'VAST-resolved', {
url: 'www.bar.foo',
previousUrl: 'www.original.foo',
wrapperDepth: 2,
error: new Error('timeout'),
duration: expect.any(Number),
statusCode: 408,
});
});
});

it('rejects with error', () => {
Expand Down Expand Up @@ -213,7 +219,6 @@ describe('VASTParser', () => {

expect(VastParser.rootURL).toBe('');
expect(VastParser.remainingAds).toEqual([]);
expect(VastParser.parentURLs).toEqual([]);
expect(VastParser.errorURLTemplates).toEqual([]);
expect(VastParser.rootErrorURLTemplates).toEqual([]);
expect(VastParser.maxWrapperDepth).toBe(5);
Expand All @@ -232,7 +237,6 @@ describe('VASTParser', () => {

expect(VastParser.rootURL).toBe('');
expect(VastParser.remainingAds).toEqual([]);
expect(VastParser.parentURLs).toEqual([]);
expect(VastParser.errorURLTemplates).toEqual([]);
expect(VastParser.rootErrorURLTemplates).toEqual([]);
expect(VastParser.maxWrapperDepth).toBe(10);
Expand Down Expand Up @@ -832,7 +836,7 @@ describe('VASTParser', () => {
wrapperBVastUrl,
1,
wrapperAVastUrl,
adWithWrapper,
adWithWrapper
);
expect(VastParser.parse).toHaveBeenCalledWith(expect.any(Object), {
url: wrapperBVastUrl,
Expand Down
11 changes: 1 addition & 10 deletions src/parser/vast_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class VASTParser extends EventEmitter {
super();

this.remainingAds = [];
this.parentURLs = [];
this.errorURLTemplates = [];
this.rootErrorURLTemplates = [];
this.maxWrapperDepth = null;
Expand Down Expand Up @@ -122,7 +121,6 @@ export class VASTParser extends EventEmitter {
url = filter(url);
});

this.parentURLs.push(url);
const timeBeforeGet = Date.now();
this.emit('VAST-resolving', {
url,
Expand Down Expand Up @@ -174,7 +172,6 @@ export class VASTParser extends EventEmitter {
withCredentials: options.withCredentials,
};
this.maxWrapperDepth = options.wrapperLimit || DEFAULT_MAX_WRAPPER_DEPTH;
this.parentURLs = [];
this.parsingOptions = { allowMultipleAds: options.allowMultipleAds };
this.remainingAds = [];
this.rootErrorURLTemplates = [];
Expand All @@ -200,7 +197,6 @@ export class VASTParser extends EventEmitter {
? util.flatten(this.remainingAds)
: this.remainingAds.shift();
this.errorURLTemplates = [];
this.parentURLs = [];

return this.resolveAds(ads, {
wrapperDepth: 0,
Expand Down Expand Up @@ -449,7 +445,6 @@ export class VASTParser extends EventEmitter {
resolveAds(ads = [], { wrapperDepth, previousUrl, url }) {
const resolveWrappersPromises = [];
previousUrl = url;

ads.forEach((ad) => {
const resolveWrappersPromise = this.resolveWrappers(
ad,
Expand Down Expand Up @@ -494,11 +489,7 @@ export class VASTParser extends EventEmitter {
delete ad.nextWrapperURL;
return resolve(ad);
}

if (
wrapperDepth >= this.maxWrapperDepth ||
this.parentURLs.indexOf(ad.nextWrapperURL) !== -1
) {
if (wrapperDepth >= this.maxWrapperDepth) {
// Wrapper limit reached, as defined by the video player.
// Too many Wrapper responses have been received with no InLine response.
ad.errorCode = 302;
Expand Down