Commit graph

95 commits

Author SHA1 Message Date
Aditya Patwardhan 31a4528302
Update to .NET 6 Preview 6 and use crossgen2 (#15763) 2021-07-19 16:06:39 -07:00
Staffan Gustafsson be7d36603d
Adding IArgumentCompleterFactory for parameterized ArgumentCompleters (#12605) 2021-03-25 17:06:40 -07:00
Aditya Patwardhan cb8165eeef
Move PSNullConditionalOperators feature out of experimental (#13529) 2020-08-27 10:11:01 -07:00
Joel Sallow (/u/ta11ow) 6aa08f9559
Improve BigInteger casting behaviours (#12629) 2020-08-04 10:45:36 +05:00
Carl Morris 2ea18ee6c9
Flag default switch statement condition clause as keyword (#10487) 2020-06-09 10:22:37 -07:00
Joel Sallow (/u/ta11ow) 7bc2617fe3
Fix string parameter binding for BigInteger numeric literals (#11634) 2020-05-12 16:31:37 -07:00
xtqqczze f4382202ae
Use correct casing for cmdlet name and cmdlet parameter name in *.ps1 files (#12584) 2020-05-07 17:00:30 +05:00
Joel Sallow (/u/ta11ow) ba53621894
Allow shorter signed hex literals with appropriate type suffixes (#11844) 2020-04-20 16:51:40 -07:00
Bryan Berns 5f89a10f5b
Added Support For Big Endian UTF-32 (#11947) 2020-04-07 14:33:15 -07:00
Steve Lee f23be437af
Fix terms checker issues (#12189) 2020-03-24 11:38:45 -07:00
Steve Lee b7cb335f03
Update copyright notice to latest guidance (#12190) 2020-03-24 11:08:37 -07:00
Tyler James Leonhardt ac1b83f152
Use Environment.NewLine instead of hard-coded linefeed in ParseError.ToString (#11746) 2020-02-03 14:03:12 -08:00
xtqqczze 920b671fb4 Unify pester test syntax for the arguments of -BeOfType (#11558) 2020-01-24 11:00:37 -08:00
xtqqczze bb58e2aab6 Correct case of $false special variable 2020-01-13 19:25:35 +00:00
xtqqczze 47a3b4e293 Correct case of $true special variable 2020-01-13 19:25:09 +00:00
xtqqczze 679702ba05 Correct case of $PSDefaultParameterValues special variable 2020-01-13 19:21:25 +00:00
xtqqczze d58e1ff13b Correct case of $MyInvocation special variable 2020-01-13 19:04:32 +00:00
xtqqczze 743983390e Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace

```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```

* Capitalise and apply hyphen to 'Not' parameter

```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```

* Capitalise and apply hyphen to 'Be' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```

* Capitalise and apply hyphen to 'BeExactly' parameter

$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'

* Capitalise and apply hyphen to 'BeGreaterThan' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```

* Use 'BeTrue' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```

* Use 'BeFalse' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```

* Capitalise and apply hyphen to 'Match' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```

* Capitalise and apply hyphen to 'Throw' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```

* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter

```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```

* Capitalise 'Because' parameter

```powershell
$_ -ireplace '\s-because\b',' -Because'
```

* Fix 'BeNullOrEmpty'
2020-01-11 20:41:59 +05:00
Ilya b221c2afa2
Correct pwsh run (#11486) 2020-01-05 12:17:41 +05:00
Aditya Patwardhan 2dbb5717ce Make null member access tests as string to avoid parsing errors (#11385)
* Make null member access tests as string to avoid parsing errors

* Add PSNullConditionalOperators feature to testmetadata.json

* Add Parsing tests to be skipped

* Add tabcompletion tests
2019-12-21 00:14:07 +00:00
Steve Lee ed1f6e3144 Make approved features non-experimental (#11303) 2019-12-10 15:41:43 -08:00
Aditya Patwardhan 2579c00a20 Support null-conditional operators ?. and ?[] in PowerShell language (#10960) 2019-11-15 16:39:53 -08:00
Aditya Patwardhan 425bc36a6f Implement Null Coalescing and Null Coalescing assignment operators (#10636) 2019-10-17 10:21:24 -07:00
Steve Lee 8cf9c01800 Add ConciseView for $ErrorView (#10641) 2019-10-04 16:52:57 -07:00
Dongbo Wang 5069c7d6a6 Support ternary operator in PowerShell language (#10367) 2019-09-04 13:22:33 -07:00
Dongbo Wang d2e81dbc13 Special case the posix locale in WildcardPattern (#10186) 2019-07-26 10:58:37 -07:00
Joel Sallow (/u/ta11ow) 17b2cec163 Cleanup Parser tests (#9792)
Co-Authored-By: Ilya <darpa@yandex.ru>
2019-06-24 11:22:54 -07:00
Dongbo Wang c684902fba Use the original precision (prior-dotnet-core-3) for double/fload-to-string conversion (#9893)
.NET Core changes to return "shortest roundtrippable string" by default for the ToString() method of double and float types. This results in ToString() for double/float values sometimes return a string in 17-digit/9-digit precision format. This PR updated the double/float-to-string conversion in PowerShell to continue using the old precision specifier before the change in .NET Core 3.0.
2019-06-19 08:56:43 +05:00
Joel Sallow (/u/ta11ow) f5e3de036e Improve whitespace for Parser tests (#9806) 2019-06-05 10:09:45 +05:00
Aditya Patwardhan 8ea15c9f13 Merged PR 8529: Add cleanup before building test package
Add cleanup before building test package
2019-05-29 00:31:14 +00:00
Steve Lee 29e21470d9 Port PowerShell to .NET Core 3.0 (#9597) 2019-05-21 13:43:51 +08:00
Kirk Munro 112401ed37 Support line continuance with pipe at the start of a line (#8938)
Expands line continuance for pipelines to allow lines to continue automatically without backticks with the pipe symbol at the start of a line.
This adds to the existing functionality where pipes can be used to continue lines by placing them at the end of a line.
2019-05-13 22:57:57 -07:00
Joel Sallow (/u/ta11ow) 3f52adb0ae Add Binary Parsing Support & Refactor TryGetNumberValue & ScanNumberHelper (#7993)
Fixes #7557 

* Adds support for binary parsing in format echoing hex: `0b11010110`
  * Works with all existing type suffixes and multipliers.
  * Supports arbitrary length parsing with `n` suffix using BigInteger; details below.
* Adds `NumberFormat` enum to specify hex/binary/base 10 for the tokenizer, replacing old `bool hex`.
* Adds `n` suffix for all numeric literals to support returning value as a `BigInteger` if requested. This bypasses the issue of large literals losing accuracy when they cast through `double`.
* Adds tests for all new behaviours.

---

### Binary / Hex Parsing Implementation

* Mimics old sign bit behaviour for int and long types. Sign bits accepted for 8 or 16-bit Hex parsing, and 8, 16, 32, 64 for binary.
  * i.e., `0xFFFFFFFF -eq ([int]-1)` and `0xFFFFFFFFFFFFFFFF -eq ([long]-1)`, but suffixing `u` creates `int.MaxValue` and `long.MaxValue`, respectively, instead.
* Sign bits higher than this are accepted for bigint-suffixed numerals:
    * Hex: Bigint-suffixed hex treats the high bit of any literal with a length multiple of 8 as the sign bit
    * Binary: Bigint-suffixed binary accepts sign bits at 96 and 128 chars, and from there on every 8 characters.
    * Prefixing the literal with a 0 will bypass this and be treated as unsigned, e.g. `0b011111111`
* Specifying an `u`nsigned suffix (or combination suffix that includes `u`) ignores sign bits, similar to how parsing a hex string using `[Convert]::ToUint32()` would do so.
* Supports negating literals using `-` prefix. This can result in positive numbers due to sign bits being permitted, just like hex literals.

---

### Refactored numeric tokenizer parsing

**New flow:**

1. Check for `real` (`.01`, `0.0`, or `0e0` syntaxes)
    1. If the decimal suffix is present, TryParse directly into decimal. If the TryParse fails, TryGetNumberValue returns `false`.
    2. TryParse as `Double`, and apply multiplier to value. If the TryParse fails, TryGetNumberValue returns `false`.
        1. Check type suffixes and attempt to cast into appropriate type. This will return `false` if the value exceeds the specified type's bounds.
        2. Default to parsing as `double` where no suffix has been applied.
2. Check number format.
    * If binary, manually parse into BigInteger using optimized helper function to directly construct the BigInteger bytes from the string.
    * If hex, TryParse into `BigInteger` using some special casing to retain original behaviours in int/long ranges.
    * If neither binary nor hex, TryParse normally as a `BigInteger`.
3. Apply multiplier value before attempting any casts to ensure type bounds can be appropriately checked without overflows.
4. Check type suffixes.
    * If a specific type suffix is used, check type bounds and attempt to parse into that type.
      * If the value exceeds the type's available values, the parse fails. Otherwise, a straight cast is performed.
5. If no suffix is used, the following types are bounds-checked, in order, resulting in the first successful test determining the type of the number. 
    * `int`
    * `long`
    * `decimal` (base-10 literals only)
    * `double` (base-10 literals only)
    * ~~`BigInteger` for binary or hex literals.~~ If the value is outside `long` range (for hex and binary) or `double` range (for base 10), the parse will fail; higher values must be explicitly requested using the `n`/`N` BigInteger suffix.

---

*This is a breaking change* as binary literals are now read as numbers instead of generic tokens which could potentially have been used as function / cmdlet names or file names.

Notes:
* Binary literal support was approved by the committee in #7557 
* ~~The same issue is still under further discussion for underscore support in numeric literals and whether BigInteger parsing ought to be exposed to the user at all.~~
    * ~~Supporting underscore literals is a further breaking change causing some generic tokens like `1_000_000` to be read as numerals instead.~~ Per @SteveL-MSFT's [comment](https://github.com/PowerShell/PowerShell/pull/7993#issuecomment-442651543) this proposal was rejected.
    * ~~Removing underscore support or preventing standard parsing from accepting BigInteger ranges is a relatively trivial matter. It is my personal opinion that there is no particular reason *not* to hand the user a BigInteger when they enter a sufficiently large literal, but I will defer to the PowerShell Committee's judgement on this.~~
2019-04-03 15:10:02 -07:00
Joel Sallow (/u/ta11ow) 130298bfae Parse numeric strings as numbers again during conversions (#8681) 2019-02-04 12:22:05 -08:00
Steve Lee 9793ed2c68 Change hashtable to use OrdinalIgnoreCase to be case-insensitive in all Cultures (#8566)
Ubuntu18.04 seems to default to C.UTF-8 for LANG (representing InvariantCulture) which results in a case-sensitive hashtable since CurrentCultureIgnoreCase doesn't work for that culture. Fix is to use OrdinalIgnoreCase instead.
2019-01-10 09:11:43 +05:00
xtqqczze 70de294fea Remove use of cmdlet aliases from .\test\powershell (#8546) 2018-12-28 13:48:23 +05:00
Travis Plunk 79f21b41de
Consolidation of all Windows PowerShell work ported to PSCore6 (#8257)
Consolidation of all Windows PowerShell work ported to PSCore6

* Added ps1 file import restriction.  Refactored InvokeLanguageModeTestingSupportCmdlet to HelpersSecurity module
* JEA loop back fix.  Debugger running commands in CL mode.
* Support for new AMSI codes.  Changed to use AMSI buffer API.  Unhandled exception fix.
* Fixes for module bugs while running in ConstrainedLanguage mode
* Untrusted input tracking work
* Configuration keyword bug fix, PSRP protocol version check for reconstruct reconnect, Sharing InitialSessionState in runspace pool.
* Restricted remote session in UMCI, Applocker detection collision, Help command exposing functions, Null reference exception fix.
* Added mitigation for debugger function exposure
2018-11-13 16:16:29 -08:00
Joel Sallow e660e9623a Add support for Byte Literals (#7901)
- Adds y suffix that is used to specify a numeric literal as the sbyte data type. 
- Can be combined with the existing u suffix as uy to specify the byte data type.
2018-10-11 17:40:58 +05:00
Joel Sallow 8f4b66af29 Add C#-style type accelerators and suffixes for ushort, uint, ulong, and short literals (#7813)
[breaking change]
Add the following type accelerators: [short], [ushort], [uint], [ulong].
Add the following numeric literal suffixes:
 - 'u' suffix (uint/ulong)
 - 's' suffix (short)
 - 'ul' suffix (ulong)
 - 'us' suffix (ushort)
2018-09-28 13:27:32 -07:00
Bruce Payette 716ed2acbd Fix a parsing error when 'break' and 'continue' are used in a switch statement in a finally block (#7273) 2018-07-13 01:19:47 -07:00
Dongbo Wang bc8abf8efa [Feature] Fix two tests 2018-07-06 13:28:20 -07:00
Dongbo Wang d2e9151fff [Feature] Add tests for experimental feature work 2018-07-06 13:28:20 -07:00
Steve Lee 6c9eea6390 Add back ADSI and WMI type accelerators (#7085) 2018-06-21 09:57:14 -07:00
Bruce Payette 3a4c410499 Fix for #6855 - Measure-Object should handle scriptblock properties. (#6934)
Measure-Object should handle `ScriptBlock` properties. Fixed by renaming `MshExpression` to `PSPropertyExpression` and making it public. Then in `MeasureObjectCommand`, lifting it up to the parameter level. Previously the implementation exposed the Property as a string and
wrapped it internally as a `PSPropertyExpression`. Now the parameter type is `PSPropertyExpression` directly allowing for both wildcard strings and `ScriptBlock`.

`PSPropertyExpression` now lives in a public namespace where it can be used by cmdlet and script authors to easily add the same type of functionality to their commands. I also modified `PSPropertyExpression` to handle hashtables properly as objects so
         @{prop = 3} | measure-object prop
and
         @{prop = 3} | measure-object {$_.prop}
will work the same. (Previously the example using just the property name would fail.)
2018-06-20 00:23:11 -07:00
Dongbo Wang b20dd31398
Fix parser to continue parsing key-value pairs after an If-Statement value in a HashExpression (#7002)
After parsing `if () { }`, new lines are skipped in order to see if either `elseif` or `else` is present. When neither is present, we should resync back to the pointer before skipping those possibly available new lines, so that the new line tokens can be utilized by the subsequent parsing.
2018-06-06 09:38:05 -07:00
Klaudia Algiz 2df9aac811 Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests (#6682)
Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests.
Get rid of try { } catch { } formula to assert that errors were thrown.
Small fixes in tests to obey the new Pester -Parameter syntax.
2018-05-17 14:42:04 -07:00
Dongbo Wang aa0af5ed56
Further improve PSMethod to Delegate conversion (#6851)
Refactor code to make it easier to maintain and a little faster. Changes are as follows:

1. Support finding a matching signature with variance. But make PowerShell prefer exact match over a match with variance.
2. The metadata signatures in `PSMethod<..>` are generated based on the array of method overloads in `MethodCacheEntry.MethodInformationStructures`, in the exact same order. So in `LanguagePrimitive.ConvertViaParseMethod`, when we try to figure out if there is a match using the metadata signatures in `PSMethod<..>`, we can get the index of the matching signature, and the same index should locate the matching method in `MethodCacheEntry.MethodInformationStructures`. Therefore, we don't need to compare signatures again in the actual conversion method, and instead, we can just leverage the index we found when figuring out the conversion in `ConvertViaParseMethod`.
   - This gets rid of the reflection call `GetMethod("Invoke")` and the subsequent signature comparisons in the final conversion method.
   - Also, when comparing signatures using `PSMethod<..>` in `ConvertViaParseMethod`, we can just use the generic argument types of each `Func<..>` metadata type, instead of calling `GetMethod("Invoke")` and then `GetParameters()`. This makes the code for comparing signatures simpler (the type `SignatureComparator`).
   - Move `MatchesPSMethodProjectedType` from `PSMemberInfo.cs` to the type `SignatureComparator` in `LanguagePrimitives.cs`, as it's closely related to the signature comparison. Also, renamed it to `ProjectedTypeMatchesTargetType`.
   - These changes make PSMethod-to-Delegate conversion a little faster, but no big improvement, as the true bottleneck probably is in delegate creation(?). Actually, the performance of this conversion is not critical at all at this moment because this feature should rarely be used in any hot script path. So this exercise is mainly for fun. 
3. Remove `PSEnum<T>`. We can directly use enum types when constructing the metadata type `Func<..>`.
4. Remove the code that generates metadata signatures for generic method definitions (call `MakeGenericMethod` with fake types like `GenericType0`, `GenericType1`). This is because:
   - We don't support convert generic method to delegate today, so may be better not spending time on preparing the metadata signature types for those methods. 
   - When the day comes that we need to support it, it's better to use generic argument types directly to construct the `Func<..>` metadata types. I left comments in `GetMethodGroupType` method in `PSMemberInfo.cs` to explain why that approach is better.
2018-05-15 11:45:04 -07:00
Robert Holt 63c0d8d783 Add error handling for interactive #requires (#6469) 2018-04-25 18:04:04 -07:00
Dongbo Wang 9df8ea58e9
Throw better parsing error when statements should be put in named block (#6434) 2018-03-21 14:24:20 -07:00
Klaudia Algiz ceef2e37e9 Use new Pester syntax: -Parameter for Pester tests in Language. (#6304) 2018-03-21 10:47:08 -07:00