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

Updates expected Adzerk URL format. #13106

Merged
merged 9 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions examples/adzerk.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
</head>
<body>
<!-- Note that the below data-r attributes are not formatted for production.
They will only work in local dev mode. --->
<amp-ad width=300 height=250
type="adzerk"
data-r="0">
<div placeholder></div>
<div fallback></div>
</amp-ad>

<amp-ad width=300 height=250
type="adzerk"
data-r="101">
<div placeholder></div>
<div fallback></div>
</amp-ad>

<amp-ad width=300 height=250
type="adzerk"
src="https://adzerk.com?id=0">
data-r="102">
<div placeholder></div>
<div fallback></div>
</amp-ad>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,13 @@ export class AmpAdNetworkAdzerkImpl extends AmpA4A {

/** @override */
getAdUrl() {
const src = this.element.getAttribute('src');
if (!/^https:\/\/adzerk.com\?id=\d+$/i.test(src)) {
return '';
}
const data = this.element.getAttribute('data-r');
dev().assert(data, 'Expected data-r attribte on amp-ad tag');
if (getMode(this.win).localDev) {
return `http://ads.localhost:${this.win.location.port}` +
'/adzerk/' + /^https:\/\/adzerk.com\?id=(\d+)/.exec(src)[1];
'/adzerk/' + data;
}
// TODO(adzerk): specify expected src path.
return /^https:\/\/adzerk.com\?id=\d+$/i.test(src) ? src : '';
return `https://engine.adzerk.net/amp?r='${encodeURIComponent(data)}'`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to encode the single quotes as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

/** @override */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describes.fakeWin('amp-ad-network-adzerk-impl', {amp: true}, env => {
fetchTextMock = sandbox.stub(Xhr.prototype, 'fetchText');
element = createElementWithAttributes(doc, 'amp-ad', {
'type': 'adzerk',
'src': 'https://adzerk.com?id=1234',
'width': '320',
'height': '50',
});
Expand All @@ -51,25 +50,17 @@ describes.fakeWin('amp-ad-network-adzerk-impl', {amp: true}, env => {

describe('#getAdUrl', () => {
it('should be valid', () => {
['https://adzerk.com?id=1234',
'https://aDzErK.com?id=1234',
'https://adzerk.com?id=9'].forEach(src => {
element.setAttribute('src', src);
expect(impl.isValidElement()).to.be.true;
expect(impl.getAdUrl()).to.equal(src);
});
const r = '{"p":[{"n":1234,"t":[5],"s":677496}]}';
element.setAttribute('data-r', r);
expect(impl.getAdUrl()).to.equal(
`https://engine.adzerk.net/amp?r='${encodeURIComponent(r)}'`);
});

it('should not be valid', () => {
['http://adzerk.com?id=1234',
'https://adzerk.com?id=a',
'https://www.adzerk.com?id=1234',
'https://adzerk.com?id=1234&a=b',
'foohttps://adzer.com?id=1234'].forEach(src => {
element.setAttribute('src', src);
expect(impl.isValidElement()).to.be.false;
expect(impl.getAdUrl()).to.equal('');
});
it('should be invalid', () => {
try {
impl.getAdUrl();
expect(false).to.be.true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no try-catch needed if you do

expect(() => imp.getAdUrl()).to.throw(/Expected data-r attribte/);

} catch (err) {}
});
});

Expand Down