Skip to content

Commit

Permalink
fix: Fix escaped slashes when passing an input to command (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski authored Aug 8, 2023
1 parent 507a520 commit 7670210
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/commands/file-requests/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FileRequestsCopyCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -50,6 +51,7 @@ FileRequestsCopyCommand.flags = {
...BoxCommand.flags,
description: flags.string({
description: 'New description of file request',
parse: utils.unescapeSlashes
}),
'expires-at': flags.string({
description: 'New date when file request expires',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/file-requests/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FileRequestsUpdateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -56,6 +57,7 @@ FileRequestsUpdateCommand.flags = {
...BoxCommand.flags,
description: flags.string({
description: 'New description of file request',
parse: utils.unescapeSlashes
}),
'expires-at': flags.string({
description: 'New date when file request expires',
Expand Down
3 changes: 2 additions & 1 deletion src/commands/files/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FilesRenameCommand extends BoxCommand {
async run() {
Expand All @@ -28,7 +29,7 @@ FilesRenameCommand.examples = ['box files:rename 11111 "New File Name.pdf"'];

FilesRenameCommand.flags = {
...BoxCommand.flags,
description: flags.string({ description: 'Change the file description' }),
description: flags.string({ description: 'Change the file description', parse: utils.unescapeSlashes }),
etag: flags.string({ description: 'Only rename if etag value matches' })
};

Expand Down
3 changes: 2 additions & 1 deletion src/commands/files/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FileUpdateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -38,7 +39,7 @@ FileUpdateCommand._endpoint = 'put_files_id';
FileUpdateCommand.flags = {
...BoxCommand.flags,
name: flags.string({ description: 'New name for the file' }),
description: flags.string({ description: 'New description for the file' }),
description: flags.string({ description: 'New description for the file', parse: utils.unescapeSlashes }),
tags: flags.string({ description: 'Set tags on the file, specified as comma-separated tags' }),
etag: flags.string({ description: 'Only apply updates if the ETag value matches' }),
'disposition-at': flags.string({ description: 'The retention expiration timestamp for the given file. This date cannot be shortened once set on a file'})
Expand Down
3 changes: 2 additions & 1 deletion src/commands/folders/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FoldersCreateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -31,7 +32,7 @@ FoldersCreateCommand._endpoint = 'post_folders';

FoldersCreateCommand.flags = {
...BoxCommand.flags,
description: flags.string({ description: 'A description for folder <DESCRIPTION>' }),
description: flags.string({ description: 'A description for folder <DESCRIPTION>', parse: utils.unescapeSlashes }),
'id-only': flags.boolean({
description: 'Return only an ID to output from this command'
})
Expand Down
3 changes: 2 additions & 1 deletion src/commands/folders/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FoldersRenameCommand extends BoxCommand {
async run() {
Expand All @@ -28,7 +29,7 @@ FoldersRenameCommand.examples = ['box folders:rename 22222 "New Folder Name"'];

FoldersRenameCommand.flags = {
...BoxCommand.flags,
description: flags.string({ description: 'Change the folder description' }),
description: flags.string({ description: 'Change the folder description', parse: utils.unescapeSlashes }),
etag: flags.string({ description: 'Only rename if etag value matches' })
};

Expand Down
3 changes: 2 additions & 1 deletion src/commands/folders/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class FoldersUpdateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -62,7 +63,7 @@ FoldersUpdateCommand.flags = {
description: 'Restricts collaborators who are not the owner of this folder from viewing other collaborations on this folder.',
allowNo: true,
}),
description: flags.string({ description: 'New description for folder' }),
description: flags.string({ description: 'New description for folder', parse: utils.unescapeSlashes }),
'upload-email-access': flags.string({
description: 'Upload email access level',
options: [
Expand Down
3 changes: 2 additions & 1 deletion src/commands/groups/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class GroupsCreateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -35,7 +36,7 @@ GroupsCreateCommand._endpoint = 'post_groups';

GroupsCreateCommand.flags = {
...BoxCommand.flags,
description: flags.string({ description: 'Description of the group' }),
description: flags.string({ description: 'Description of the group', parse: utils.unescapeSlashes }),
'external-sync-identifier': flags.string({
description: 'Group identifier for groups coming from an external source',
}),
Expand Down
3 changes: 2 additions & 1 deletion src/commands/groups/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class GroupsUpdateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -42,7 +43,7 @@ GroupsUpdateCommand.flags = {
char: 'n',
description: 'The name of the group',
}),
description: flags.string({ description: 'Description of the group' }),
description: flags.string({ description: 'Description of the group', parse: utils.unescapeSlashes }),
'external-sync-identifier': flags.string({ description: 'group identifier for groups coming from an external source' }),
provenance: flags.string({ description: 'Track the external source where the group is coming from' }),
invite: flags.string({
Expand Down
3 changes: 2 additions & 1 deletion src/commands/legal-hold-policies/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class LegalHoldPoliciesCreateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -32,7 +33,7 @@ LegalHoldPoliciesCreateCommand._endpoint = 'post_legal_hold_policies';

LegalHoldPoliciesCreateCommand.flags = {
...BoxCommand.flags,
description: flags.string({ description: 'Description of legal hold policy' }),
description: flags.string({ description: 'Description of legal hold policy', parse: utils.unescapeSlashes }),
'filter-started-at': flags.string({
description: 'Date filter applies to Custodian assignments only. Should be today\'s date or before. Use a RFC3339 timestamp or shorthand syntax 0t, like -5w for 5 weeks ago',
dependsOn: ['filter-ended-at'],
Expand Down
3 changes: 2 additions & 1 deletion src/commands/legal-hold-policies/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class LegalHoldPoliciesUpdateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -29,7 +30,7 @@ LegalHoldPoliciesUpdateCommand._endpoint = 'put_legal_hold_policies_id';

LegalHoldPoliciesUpdateCommand.flags = {
...BoxCommand.flags,
description: flags.string({ description: 'Description of legal hold policy. Max characters 500' }),
description: flags.string({ description: 'Description of legal hold policy. Max characters 500', parse: utils.unescapeSlashes }),
'policy-name': flags.string({ description: 'Name of legal hold policy. Max characters 254' }),
'release-notes': flags.string({ description: 'Notes around why the policy was released. Max characters 500' })
};
Expand Down
4 changes: 3 additions & 1 deletion src/commands/retention-policies/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class RetentionPoliciesCreateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -95,7 +96,8 @@ RetentionPoliciesCreateCommand.flags = {
}),
description: flags.string({
required: false,
description: 'The additional text description of the retention policy'
description: 'The additional text description of the retention policy',
parse: utils.unescapeSlashes
}),
'custom-notification-recipient': flags.string({
description: 'A list of users notified when the retention policy duration is about to end. ' +
Expand Down
4 changes: 3 additions & 1 deletion src/commands/web-links/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class WebLinksCreateCommand extends BoxCommand {
async run() {
Expand All @@ -28,7 +29,8 @@ WebLinksCreateCommand.flags = {
...BoxCommand.flags,
description: flags.string({
char: 'd',
description: 'Description of the web link'
description: 'Description of the web link',
parse: utils.unescapeSlashes
}),
name: flags.string({
char: 'n',
Expand Down
4 changes: 3 additions & 1 deletion src/commands/web-links/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const utils = require('../../util');

class WebLinksUpdateCommand extends BoxCommand {
async run() {
Expand Down Expand Up @@ -31,7 +32,8 @@ WebLinksUpdateCommand.flags = {
...BoxCommand.flags,
description: flags.string({
char: 'd',
description: 'Description of the web link'
description: 'Description of the web link',
parse: utils.unescapeSlashes
}),
name: flags.string({
char: 'n',
Expand Down
14 changes: 14 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ module.exports = {
return path.resolve(value);
},

/**
* Unescape slashes from the given string.
*
* @param {string} value The raw string which can contains escaped slashes
* @returns {string} A string with unescaped escaping in newline and tab characters.
*/
unescapeSlashes(value) {
try {
return JSON.parse(`"${value}"`);
} catch (e) {
return value;
}
},

/**
* Parses the key=val string format for metadata into an object {key: val}
*
Expand Down
2 changes: 1 addition & 1 deletion test/commands/folders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ describe('Folders', () => {
describe('folders:update', () => {
let folderId = '0',
name = 'New Folder',
description = 'New description',
description = 'New \ndescription',
tags = 'foo,bar',
fixture = getFixture('folders/put_folders_id'),
yamlOutput = getFixture('output/folders_update_yaml.txt');
Expand Down

0 comments on commit 7670210

Please sign in to comment.