Skip to content

Commit

Permalink
Encode characters in file paths to ensure proper URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Aug 14, 2019
1 parent a728ed1 commit a321145
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ui/app/adapters/task-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export default ApplicationAdapter.extend({

ls(model, path) {
return this.token
.authorizedRequest(`/v1/client/fs/ls/${model.allocation.id}?path=${path}`)
.authorizedRequest(`/v1/client/fs/ls/${model.allocation.id}?path=${encodeURIComponent(path)}`)
.then(handleFSResponse);
},

stat(model, path) {
return this.token
.authorizedRequest(`/v1/client/fs/stat/${model.allocation.id}?path=${path}`)
.authorizedRequest(
`/v1/client/fs/stat/${model.allocation.id}?path=${encodeURIComponent(path)}`
)
.then(handleFSResponse);
},
});
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/fs-directory-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default Component.extend({

pathToEntry: computed('path', 'entry.Name', function() {
const pathWithNoLeadingSlash = this.get('path').replace(/^\//, '');
const name = this.get('entry.Name');
const name = encodeURIComponent(this.get('entry.Name'));

if (isEmpty(pathWithNoLeadingSlash)) {
return name;
Expand Down
4 changes: 3 additions & 1 deletion ui/app/components/task-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default Component.extend({
isStreaming: false,

catUrl: computed('allocation.id', 'task.name', 'file', function() {
return `/v1/client/fs/cat/${this.allocation.id}?path=${this.task.name}/${this.file}`;
const encodedPath = encodeURIComponent(`${this.task.name}/${this.file}`);
return `/v1/client/fs/cat/${this.allocation.id}?path=${encodedPath}`;
}),

fetchMode: computed('isLarge', 'mode', function() {
Expand Down Expand Up @@ -77,6 +78,7 @@ export default Component.extend({
),

fileParams: computed('task.name', 'file', 'mode', function() {
// The Log class handles encoding query params
const path = `${this.task.name}/${this.file}`;

switch (this.mode) {
Expand Down
2 changes: 1 addition & 1 deletion ui/mirage/factories/alloc-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Factory, faker, trait } from 'ember-cli-mirage';
import { pickOne } from '../utils';

const REF_TIME = new Date();
const TROUBLESOME_CHARACTERS = '🏆 💃 🤩 🙌🏿 🖨 ? / + ; %'.split(' ');
const TROUBLESOME_CHARACTERS = '🏆 💃 🤩 🙌🏿 🖨 ? ; %'.split(' ');
const makeWord = () => Math.round(Math.random() * 10000000 + 50000).toString(36);
const makeSentence = (count = 10) =>
new Array(count)
Expand Down
1 change: 0 additions & 1 deletion ui/tests/acceptance/task-fs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ module('Acceptance | task fs', function(hooks) {
test('viewing a file', async function(assert) {
const node = server.db.nodes.find(allocation.nodeId);

server.logging = true;
server.get(`http://${node.httpAddr}/v1/client/fs/readat/:allocation_id`, function() {
return new Response(500);
});
Expand Down
4 changes: 3 additions & 1 deletion ui/tests/integration/task-file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ module('Integration | Component | task file', function(hooks) {
const rawLink = find('[data-test-log-action="raw"]');
assert.equal(
rawLink.getAttribute('href'),
`/v1/client/fs/cat/${props.allocation.id}?path=${props.task.name}/${props.file}`,
`/v1/client/fs/cat/${props.allocation.id}?path=${encodeURIComponent(
`${props.task.name}/${props.file}`
)}`,
'Raw link href is correct'
);

Expand Down

0 comments on commit a321145

Please sign in to comment.