Skip to content

Faulty regex and usage of to_s triggers unwanted warning #379

@mariastroe

Description

@mariastroe

Version:

chef-vault-4.1.3

Environment:

Alpine Linux

Scenario:

As the new version of the chef-vault gem was released (4.1.3), when doing
knife vault create env secrets -M client -J creds.json -A admin1 -C "client1,client2"
it shows a warning
WARN: Value '[{:api_version=>"api/v3", :metadata=>{}, :data=>{:enabled=>true, :groups=>["test"], :password=>"testpass", :username=>"test"}, :type=>"User"}]' of key 'users' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\Windows) in double-quoted strings.

Expected Result:

Not printing any warning.
Not printing the value of the key in the warning.
An accurate suggestion in the warning because in my case i don't have any backslashes but actually whitespaces.

Additional Context:

In lib/chef/knife/mixin/helper.rb, the printable? function uses match (which returns a MatchData object when a match is found, or nil if no matches found) instead of match? (which actually returns true if match is found and false if not, as stated in the comments).
Also, because of the usage of to_s in printable?(value.to_s), the value is pretty-printed and matches the [[:space:]] if you have values like "a b c" or like mine (in the scenario above). Leaving the regex just with [^[:print:]] like it was before would solve the problem and not trigger any warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Triage: ConfirmedIndicates and issue has been confirmed as described.Type: BugDoes not work as expected.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions