Skip to content

Command.js mutates the options array #9929

@JFGHT

Description

@JFGHT

[REQUIRED] Environment info

firebase-tools: 15.6.0

Platform: macOS

[REQUIRED] Test case

import firebaseTools from 'firebase-tools';

const PROJECT = 'test';

console.log('1st call...');
try { await firebaseTools.use(PROJECT); } catch (e) { console.error('1st:', e.message); }

console.log('2nd call...');
try { await firebaseTools.use(PROJECT); } catch (e) { console.error('2nd:', e.message); }

console.log('3rd call...');
try { await firebaseTools.use(PROJECT); } catch (e) { console.error('3rd:', e.message); }

[REQUIRED] Steps to reproduce

Just run the provided code.

[REQUIRED] Expected behavior

Should not throw.

[REQUIRED] Actual behavior

Throws with Cannot read properties of undefined (reading 'indexOf').

For the issue you can point to lib/command.js args.shift() destructively mutates the option arrays on each register() call.
Fix proposal: use destructuring ([flags, ...args]) instead. Example:

this.options.forEach(([flags, ...args]) => {
  cmd.option(flags, ...args);
});

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions