Skip to content

Commit

Permalink
ui: URL encodes any varaibles interpolated into the template... (#5766)
Browse files Browse the repository at this point in the history
Encodes any variables passed in to be used for template interpolation, but importantly nothing else in the URL apart from the variables themselves. 'Generally' service names are reasonably URL safe, but we know of usecases using at least /s in service names.
  • Loading branch information
johncowen authored and John Cowen committed May 2, 2019
1 parent 6f9dcb4 commit 71c0db4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ui-v2/app/components/templated-anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default Component.extend({
if (typeof vars !== 'undefined' && typeof value !== 'undefined') {
value = value.replace(templateRe, function(match, group) {
try {
return get(vars, group) || '';
return encodeURIComponent(get(vars, group) || '');
} catch (e) {
return '';
}
Expand Down
16 changes: 14 additions & 2 deletions ui-v2/tests/integration/components/templated-anchor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('it renders', function(assert) {
Name: '{{Name}}',
ID: '{{ID}}',
},
result: 'http://localhost/?={{Name}}/{{ID}}',
result: 'http://localhost/?=%7B%7BName%7D%7D/%7B%7BID%7D%7D',
},
{
href: 'http://localhost/?={{deep.Name}}/{{deep.ID}}',
Expand All @@ -31,14 +31,16 @@ test('it renders', function(assert) {
ID: '{{ID}}',
},
},
result: 'http://localhost/?={{Name}}/{{ID}}',
result: 'http://localhost/?=%7B%7BName%7D%7D/%7B%7BID%7D%7D',
},
{
href: 'http://localhost/?={{}}/{{}}',
vars: {
Name: 'name',
ID: 'id',
},
// If you don't pass actual variables then nothing
// gets replaced and nothing is URL encoded
result: 'http://localhost/?={{}}/{{}}',
},
{
Expand Down Expand Up @@ -81,6 +83,16 @@ test('it renders', function(assert) {
},
result: 'http://localhost/?=',
},
{
href: 'http://localhost/?={{deep.Name}}',
vars: {
deep: {
Name: '#Na/me',
ID: 'ID',
},
},
result: 'http://localhost/?=%23Na%2Fme',
},
].forEach(item => {
this.set('item', item);
this.render(hbs`
Expand Down

0 comments on commit 71c0db4

Please sign in to comment.