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

Don't encode ExpandStringAsync #19161

Merged
merged 3 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
don't encode
  • Loading branch information
calebcordry committed Nov 6, 2018
commit 6b08bd7df60d3fa935eac127ae0afaaeefb68198
2 changes: 1 addition & 1 deletion build-system/amp4test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ app.use('/compose-doc', function(req, res) {
<head>
<meta charset="utf-8">
<link rel="canonical" href="http://nonblocking.io/" >
<title>AMP-TEST</title>
<title>AMP TEST</title>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
${metaTag}
<script>
Expand Down
11 changes: 8 additions & 3 deletions src/service/url-expander/expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export class Expander {
* @param {boolean=} opt_sync If the method should resolve syncronously.
* @param {!Object<string, boolean>=} opt_whiteList Optional white list of names
* that can be substituted.
* @param {boolean=} opt_noEncode Should not urlEncode macro resolution.
*/
constructor(variableSource, opt_bindings, opt_collectVars, opt_sync,
opt_whiteList) {
opt_whiteList, opt_noEncode) {

/** @const {?../variable-source.VariableSource} */
this.variableSource_ = variableSource;
Expand All @@ -59,6 +60,9 @@ export class Expander {

/**@const {!Object<string, boolean>|undefined} */
this.whiteList_ = opt_whiteList;

/**@const {boolean|undefined} */
this.noEncode_ = opt_noEncode;
}


Expand Down Expand Up @@ -294,10 +298,11 @@ export class Expander {

if (val == null) {
result = '';
} else if (this.noEncode_ || NOENCODE_WHITELIST[name]) {
result = val;
} else {
result = NOENCODE_WHITELIST[name] ? val : encodeURIComponent(val);
result = encodeURIComponent(val);
}

return result;
}).catch(e => {
rethrowAsync(e);
Expand Down
3 changes: 2 additions & 1 deletion src/service/url-replacements-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ export class UrlReplacements {
opt_bindings,
/* opt_collectVars */ undefined,
/* opt_sync */ undefined,
opt_whiteList)./*OK*/expand(source));
opt_whiteList,
/* opt_noEncode */ true)./*OK*/expand(source));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/functional/test-url-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,17 @@ describes.sandboxed('UrlReplacements', {}, () => {
expect(expanded).to.equal('abc:X:Y');
});
});

it.only('should not encode values returned by expandStringAsync', () => {
const win = getFakeWindow();
const urlReplacements = Services.urlReplacementsForDoc(win.ampdoc);
return urlReplacements.expandStringAsync(
'title=TITLE',
{'TITLE': Promise.resolve('test with spaces')},
).then(expanded => {
expect(expanded).to.equal('title=test with spaces');
});
});
});

describe('Expanding Input Value', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/test-amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe.configure().skipIfPropertiesObfuscated().run('amp' +
}, env => {
it('should send request', () => {
return withdrawRequest(
env.win, 'analytics-basic?a=2&b=AMP-TEST').then(request => {
env.win, 'analytics-basic?a=2&b=AMP%20TEST').then(request => {
expect(request.headers.referer,
'should keep referrer if no referrerpolicy specified').to.be.ok;
});
Expand Down Expand Up @@ -98,7 +98,7 @@ describe.configure().skipIfPropertiesObfuscated().run('amp' +
}, env => {
it('should send request in batch', () => {
return withdrawRequest(env.win,
'analytics-batch?a=1&b=AMP-TEST&a=1&b=AMP-TEST');
'analytics-batch?a=1&b=AMP%20TEST&a=1&b=AMP%20TEST');
});
});

Expand Down Expand Up @@ -136,7 +136,7 @@ describe.configure().skipIfPropertiesObfuscated().run('amp' +
it('should send request use POST body payload', () => {
return withdrawRequest(
env.win, 'analytics-useBody').then(request => {
expect(request.body).to.equal('{"a":2,"b":"AMP-TEST"}');
expect(request.body).to.equal('{"a":2,"b":"AMP TEST"}');
});
});
});
Expand Down Expand Up @@ -184,7 +184,7 @@ describe.configure().skipIfPropertiesObfuscated().run('amp' +
return withdrawRequest(
env.win, 'analytics-batch-useBody').then(request => {
expect(request.body).to
.equal('[{"a":1,"b":"AMP-TEST"},{"a":1,"b":"AMP-TEST"}]');
.equal('[{"a":1,"b":"AMP TEST"},{"a":1,"b":"AMP TEST"}]');
});
});
});
Expand Down