diff --git a/modules/atomxBidAdapter.js b/modules/atomxBidAdapter.js index 383547af3ec..69bb04a227b 100644 --- a/modules/atomxBidAdapter.js +++ b/modules/atomxBidAdapter.js @@ -32,7 +32,7 @@ var AtomxAdapter = function AtomxAdapter() { id: bid.params.id, size: sizes[j], prebid: bid.placementCode - }, {method: 'GET'}); + }, {method: 'GET', noDecodeWholeURL: true}); } } else { var bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bid); diff --git a/src/ajax.js b/src/ajax.js index 02b699d7e9a..44ff00a0fe0 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -76,7 +76,7 @@ export function ajax(url, callback, data, options = {}) { } if (method === 'GET' && data) { - let urlInfo = parseURL(url); + let urlInfo = parseURL(url, options); Object.assign(urlInfo.search, data); url = formatURL(urlInfo); } diff --git a/src/url.js b/src/url.js index 0682ece573a..5bfeb9c3151 100644 --- a/src/url.js +++ b/src/url.js @@ -24,9 +24,13 @@ export function formatQS(query) { .join('&'); } -export function parse(url) { +export function parse(url, options) { let parsed = document.createElement('a'); - parsed.href = decodeURIComponent(url); + if (options && 'noDecodeWholeURL' in options && options.noDecodeWholeURL) { + parsed.href = url; + } else { + parsed.href = decodeURIComponent(url); + } return { protocol: (parsed.protocol || '').replace(/:$/, ''), hostname: parsed.hostname, diff --git a/test/spec/url_spec.js b/test/spec/url_spec.js index 2b60549ef63..3ffb8ad5ca7 100644 --- a/test/spec/url_spec.js +++ b/test/spec/url_spec.js @@ -6,7 +6,7 @@ describe('helpers.url', () => { let parsed; beforeEach(() => { - parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar#hash'); + parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash'); }); it('extracts the protocol', () => { @@ -28,8 +28,9 @@ describe('helpers.url', () => { it('extracts the search query', () => { expect(parsed).to.have.property('search'); expect(parsed.search).to.eql({ - foo: 'bar', - search: 'test' + foo: 'xxx', + search: 'test', + bar: 'foo', }); }); @@ -42,6 +43,23 @@ describe('helpers.url', () => { }); }); + describe('parse(url, {noDecodeWholeURL: true})', () => { + let parsed; + + beforeEach(() => { + parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash', {noDecodeWholeURL: true}); + }); + + it('extracts the search query', () => { + expect(parsed).to.have.property('search'); + expect(parsed.search).to.eql({ + foo: 'bar', + search: 'test', + bar: 'foo%26foo%3Dxxx', + }); + }); + }); + describe('format()', () => { it('formats an object in to a URL', () => { expect(format({ @@ -49,9 +67,9 @@ describe('helpers.url', () => { hostname: 'example.com', port: 3000, pathname: '/pathname/', - search: {foo: 'bar', search: 'test'}, + search: {foo: 'bar', search: 'test', bar: 'foo%26foo%3Dxxx'}, hash: 'hash' - })).to.equal('http://example.com:3000/pathname/?foo=bar&search=test#hash'); + })).to.equal('http://example.com:3000/pathname/?foo=bar&search=test&bar=foo%26foo%3Dxxx#hash'); }); it('will use defaults for missing properties', () => {