Skip to content

Commit

Permalink
Merge pull request #323 from backspace/trim-choices
Browse files Browse the repository at this point in the history
Add trimming of choice input
  • Loading branch information
SBoudrias committed Jan 17, 2016
2 parents 9ce4983 + 54a947e commit d7ffce5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/prompts/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Prompt.prototype.onSubmit = function( input ) {
input = this.rawDefault;
}

var selected = this.opt.choices.where({ key : input.toLowerCase() })[0];
var selected = this.opt.choices.where({ key : input.toLowerCase().trim() })[0];

if ( selected != null && selected.key === "h" ) {
this.selectedKey = "";
Expand Down
8 changes: 8 additions & 0 deletions test/specs/prompts/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ describe("`expand` prompt", function() {
this.rl.emit("line", "b");
});

it("should strip the user input", function( done ) {
this.expand.run(function( answer ) {
expect(answer).to.equal("bar");
done();
});
this.rl.emit("line", " b ");
});

it("should have help option", function( done ) {
var run = 0;
this.expand.run(function( answer ) {
Expand Down

0 comments on commit d7ffce5

Please sign in to comment.