Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make property to treat empty strings as not defined values #60

Closed
nightroman opened this issue Apr 10, 2017 · 0 comments
Closed

Make property to treat empty strings as not defined values #60

nightroman opened this issue Apr 10, 2017 · 0 comments

Comments

@nightroman
Copy link
Owner

nightroman commented Apr 10, 2017

Current behavior

  • get the session variable value if it is not $null
  • get the environment value if it is not $null
  • get the specified default if it is not $null
  • error

Proposed behavior

  • get the session variable value if it is not $null or ''
  • get the environment value if it is not $null or ''
  • get the specified default if it is not $null
  • error

Note that '' is still allowed as the default value. It is up to a developer to specify it and avoid errors or omit it and allow errors.

Thoughts

(1) Properties are mostly strings because one of their sources is environment variables which are strings.

(2) PowerShell assigns empty strings as default values of strongly typed string variables. Example: default script parameters and variables declared as [string]. Even assigning $null explicitly results in the empty string actually assigned. Thus, empty strings should be treated as not defined. Otherwise, we have to drop useful strong typing, see #59 (comment)

(3) The proposed behavior aligns with MSBuild properties. Example: in MSBuild Condition="'$(MyProperty)' == ''" not defined $(MyProperty) (i.e. currently $null in PowerShell properties) and an empty string are treaded in the same way, "not defined".

Caveat

In theory, such a change may break some code. But empty strings are unlikely used as meaningful properties in practice. So we are not going to treat this as a major change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant