Skip to content

Commit b97d8d6

Browse files
Replace PostScribe in the PUC (#246)
* Remove deprecated postscribe * Fix mobile-app rendering when admarkup contains lowercase DOCTYPE tag
1 parent a599103 commit b97d8d6

5 files changed

+22
-17
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"webpack-common-shake": "^1.0.0"
7777
},
7878
"dependencies": {
79-
"babel-plugin-transform-object-assign": "^6.22.0",
80-
"postscribe": "^2.0.8"
79+
"babel-plugin-transform-object-assign": "^6.22.0"
8180
}
8281
}

src/adHtmlRender.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function writeAdHtml(markup, insertHTML = document.body.insertAdjacentHTML.bind(document.body)) {
2+
// remove <?xml> and <!doctype> tags
3+
// https://github.com/prebid/prebid-universal-creative/issues/134
4+
markup = markup.replace(/\<(\?xml|(\!DOCTYPE[^\>\[]+(\[[^\]]+)?))+[^>]+\>/gi, '');
5+
6+
try {
7+
insertHTML('beforeend', markup);
8+
} catch (error) {
9+
console.error(error);
10+
}
11+
}

src/mobileAndAmpRender.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCreativeCommentMarkup, triggerPixel, createTrackPixelHtml, loadScript, getCreativeComment, writeAdUrl, transformAuctionTargetingData, sendRequest, getUUID } from './utils';
22
import { isSafeFrame, isMobileApp } from './environment';
33
import { insertElement } from './domHelper';
4-
import { writeAdHtml } from './postscribeRender';
4+
import { writeAdHtml } from './adHtmlRender';
55

66
const DEFAULT_CACHE_HOST = 'prebid.adnxs.com';
77
const DEFAULT_CACHE_PATH = '/pbc/v1/cache';
@@ -151,7 +151,6 @@ function responseCallback(isMobileApp, hbPb) {
151151
if (isMobileApp) {
152152
let adhtml = loadScript(window, bidObject.nurl);
153153
ad += constructMarkup(adhtml.outerHTML, width, height);
154-
155154
writeAdHtml(ad);
156155
} else {
157156
let nurl = bidObject.nurl;

src/postscribeRender.js

-10
This file was deleted.

test/spec/mobileAndAmpRender_spec.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { renderAmpOrMobileAd } from 'src/mobileAndAmpRender';
2-
import * as postscribeRender from 'src/postscribeRender'
2+
import * as postscribeRender from 'src/adHtmlRender'
33
import * as utils from 'src/utils';
44
import { expect } from 'chai';
55
import { mocks } from 'test/helpers/mocks';
66
import { merge } from 'lodash';
7-
import {writeAdHtml} from 'src/postscribeRender';
7+
import {writeAdHtml} from 'src/adHtmlRender';
88

99

1010
function renderingMocks() {
@@ -312,5 +312,11 @@ describe('writeAdHtml', () => {
312312
const ps = sinon.stub();
313313
writeAdHtml('<!DOCTYPE html><div>mock-ad</div>', ps);
314314
sinon.assert.calledWith(ps, sinon.match.any, '<div>mock-ad</div>')
315-
})
315+
});
316+
317+
it('removes lowercase doctype from markup', () => {
318+
const ps = sinon.stub();
319+
writeAdHtml('<!doctype html><div>mock-ad</div>', ps);
320+
sinon.assert.calledWith(ps, sinon.match.any, '<div>mock-ad</div>')
321+
});
316322
})

0 commit comments

Comments
 (0)