Encode characters in file paths to ensure proper URIs

This commit is contained in:
Michael Lange 2019-08-12 13:51:38 -07:00
parent 38fce53936
commit 836e7426b8
6 changed files with 12 additions and 7 deletions

View file

@ -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);
},
});

View file

@ -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;

View file

@ -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() {
@ -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) {

View file

@ -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)

View file

@ -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);
});

View file

@ -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'
);