Inquirer.js: SyntaxError thrown if CLI width cannot be obtained

Created on 29 Sep 2015  路  6Comments  路  Source: SBoudrias/Inquirer.js

If cli-width returns 0, which is possible in certain environments, Inquirer will crash on line 108 of lib/utils/screen-manager.js:

  var regex = new RegExp('.{1,' + cliWidth() + '}', 'g');

/.{1,0}/g is an invalid regex as the max number of characters is smaller than the minimum. This throws an error:

SyntaxError: Invalid regular expression: /.{1,0}/: numbers out of order in {} quantifier.

The cli-width package supports setting the default width to a number other than 0 by setting the value of cliWidth.defaultWidth. It seems reasonable to have a default of 80 instead of 0.

bug

Most helpful comment

:+1: got this bug on WIndows.

All 6 comments

:+1: got this bug on WIndows.

@SBoudrias is there any news about this bug?

@artem-malko Feel free to send a PR.

Just encountered this one too when users of my app were attempting to execute a script in the Intellij shell.

I've sent a PR for setting the default value to 80. I've experimented with it in a Windows 10 PC and seems to be working fine.

Omitting tests since screen-manager.js it not being unit tested at all.

A temporary fix is setting an environment variable named CLI_WIDTH to anything greater than 1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ro31337 picture ro31337  路  5Comments

apierzch picture apierzch  路  4Comments

sindresorhus picture sindresorhus  路  4Comments

XhmikosR picture XhmikosR  路  7Comments

aaronshaf picture aaronshaf  路  7Comments