Skip to content

Error can occur if no default is specified and an empty line is entered #23

Description

@greenonline

Reproduction steps

Call get_reply() with no default specified. Enter a bad/ invalid input. Then at the invalid selection" prompt, just hit enter:

Invalid selection, please try again:                                            
Use of uninitialized value $answer in split at UI.pm line nnn.

Fix

This issue can be easily fixed by checking to see if $answer is undefined after it is assigned $default in _tt_readline().

Adding:

        ### If no default specified, then we could end up with an undefined value
        if (!defined $answer){
            ### Set to empty string to avoid split error later
            $answer = "";
        }

to

        ### pose the question
        my $answer = defined $preput
          ? $term->readline($prompt, $preput)
          : $term->readline($prompt);

        $answer     = $default unless length $answer;

like so

        ### pose the question
        my $answer = defined $preput
          ? $term->readline($prompt, $preput)
          : $term->readline($prompt);

        $answer     = $default unless length $answer;

        ### If no default specified, then we could end up with an undefined value
        if (!defined $answer){
            ### Set to empty string to avoid split error later
            $answer = "";
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions