Skip to content

Commit

Permalink
Add url.parse option to not decode the whole URL
Browse files Browse the repository at this point in the history
See: #1480
  • Loading branch information
erikdubbelboer committed Aug 21, 2017
1 parent 6956a56 commit 5342c43
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/atomxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions test/spec/url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {noDecodeWholeURL: true});
});

it('extracts the protocol', () => {
Expand All @@ -29,7 +29,8 @@ describe('helpers.url', () => {
expect(parsed).to.have.property('search');
expect(parsed.search).to.eql({
foo: 'bar',
search: 'test'
search: 'test',
bar: 'foo%26foo%3Dxxx',
});
});

Expand All @@ -49,9 +50,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', () => {
Expand Down

0 comments on commit 5342c43

Please sign in to comment.