GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enable use 'Singleline,Multiline' option in split operator by iSazonov · Pull Request #4721 · PowerShell/PowerShell

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Aug 31, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Fix #4712

RegEx Singleline and Multiline options are not mutually exclusive and can be used at the same time.

Tests for -split operator is added to get real code coverage and exclude regressions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov Ilya (iSazonov) assigned Jason Shirk (lzybkr) Aug 31, 2017
@iSazonov
Ilya (iSazonov) requested review from Bruce Payette (BrucePay), Dongbo Wang (daxian-dbw), Jason Shirk (lzybkr) and sergei (vors) as code owners August 31, 2017 14:10
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-already-signed label Aug 31, 2017
@iSazonov
Enable use 'Singleline,Multiline' option in split operator
75b0a41
@iSazonov
Ilya (iSazonov) force-pushed the fix-split branch from a5ca6bd to 75b0a41 Compare August 31, 2017 14:49
vors
sergei (vors) approved these changes Sep 1, 2017
View reviewed changes
Comment thread test/powershell/Language/Operators/SplitOperator.Tests.ps1 Outdated
Context "Binary split operator options" {
BeforeAll {
$testText = "a12a`nb34b`nc56c`nd78d"
# Add '#' - now second line do not start with 'b'.

@vors sergei (vors) Sep 1, 2017

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use some other char instead of # - it's easy to confuse with comments, but comments are irrelevant here.

also nit: doesn't start

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@iSazonov Ilya (iSazonov) Sep 4, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/powershell/Language/Operators/SplitOperator.Tests.ps1
}

It "Unary split operator can split array of values" {
$res = -split ("a b", "c d")

@vors sergei (vors) Sep 1, 2017

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow didn't know you can do that!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mklement0 Michael Klement (mklement0) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sergei (@vors):
Turns out I didn't know either, mostly because the documentation:

  • in part suggests that only string scalars are supported (<String> in the syntax diagram)

  • where it does mention arrays (multiple input strings), mistakenly claims that only the binary form supports them ("To split more than one string, use the binary split operator ").

I've created a doc issue to address that.

(I originally thought that when you pass an array it simply gets stringified based on $OFS, but that's not the case.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov
Fix typo and replace 'special' symbol
fe4374a
lzybkr
Jason Shirk (lzybkr) reviewed Sep 5, 2017
View reviewed changes
Comment thread test/powershell/Language/Operators/SplitOperator.Tests.ps1
$res[2] | Should Be "c"
$res[3] | Should Be "d"

$res = "a b c d" -split " ", -1

@lzybkr Jason Shirk (lzybkr) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid scenario, or should PowerShell report an error when the count is less than 1?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Sep 5, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this from our documentation - see <Max-substrings>.
So it will be a breaking change if we add a exception here. I don't see the need for that.

Michael Klement (@mklement0) Could you please comment too?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mklement0 Michael Klement (mklement0) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ilya (@iSazonov): Yes, the documentation states "A value of 0 and negative values return all the substrings".

Supporting 0 definitely makes sense, because in order to be able to specify options you must also specify a <max-substrings> value for syntactical reasons, so you need a way to signal the default of "return all".

Negative values serve no real purpose - and could lead people to mistakenly assume that they have special meaning - but given that they're documented and that we could break existing code, I don't think a change is warranted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@iSazonov Ilya (iSazonov) Sep 5, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Michael Klement (@mklement0) Thanks for good comment!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mklement0 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@lzybkr Jason Shirk (lzybkr) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an argument in favor of a breaking change - is a negative count a likely bug? For example, if I compute the count and swapped my operands, this feels like a bug PowerShell should catch.

I do think it's an unlikely breaking change, mostly because the count it most commonly a constant.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lzybkr Jason Shirk (lzybkr) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant something like:

$cnt = $b - $a # Should have been $a - $b
'a b c d' -split ' ', $cnt

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mklement0 Michael Klement (mklement0) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks. Preventing negative values categorically is certainly at odds with what I just proposed, but I'd still consider it an improvement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Sep 6, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is interesting improvement:

PS C:\temp> 'a b c d' -split ' ', 2
a
b c d
PS C:\temp> 'a b c d' -split ' ', 1
a b c d
PS C:\temp> 'a b c d' -split ' ', 0
a
b
c
d
PS C:\temp> 'a b c d' -split ' ', -1
a b c d
PS C:\temp> 'a b c d' -split ' ', -2
a b c
d

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mklement0 Michael Klement (mklement0) Sep 6, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ilya (@iSazonov): Yes, though your -2 behavior is what I suggest for -1 - analogous to index [-1] retrieving the last element of a collection.
Not sure if providing a way to not split at all is necessary.

> 'a b c d' -split ' ', -1  # last 1
a b c
d

> 'a b c d' -split ' ', -2  # last 2
a b
c
d

Also, it's probably worth always returning a first item that represents the remaining, unsplit part - even if that part is empty:

> 'a b' -split ' ', -2  # last 2, with nothing remaining
   # empty string  to signal that there's no remaining part
a
b

That enables the following idiom, irrespective of whether there's a remaining part (prefix) or not.

> $prefix, $tokens = 'a b' -split ' ', -2

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Sep 6, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Michael Klement (@mklement0) I like the "breaking change". If Jason Shirk (@lzybkr) approve we should open Issue Enhancement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mklement0 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
lzybkr
Jason Shirk (lzybkr) reviewed Sep 5, 2017
View reviewed changes
Comment thread test/powershell/Language/Operators/SplitOperator.Tests.ps1 Outdated

Context "Binary split operator options" {
BeforeAll {
$testText = "a12a`nb34b`nc56c`nd78d"

@lzybkr Jason Shirk (lzybkr) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-line tests should probably all test the three linefeed variants: `n, `r, and `r`n.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Sep 5, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we is full based on RegEx implementation in our code. We don't parse the string, we only pass it to RegEx as is. Do we really want to test CoreFX implementation?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lzybkr Jason Shirk (lzybkr) Sep 5, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True today and probably true forever, but if somebody decided they could be smarter than regex (maybe in limited scenarios), it's useful (if it's easy) to cover those additional scenarios.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Sep 5, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. I added tests for 'n' and 'rn'. SingleLine option catch only 'n so I believe no tests needed for 'r'.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lzybkr
Jason Shirk (lzybkr) approved these changes Sep 5, 2017
View reviewed changes

@lzybkr Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but it would be nice to see more tests with the various valid variants of line feeds.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov
Add tests for 'n' and 'r`n' line separators
a99f9bd
@lzybkr

Jason Shirk (lzybkr) commented Sep 6, 2017

Copy link
Copy Markdown
Contributor

I approve of the breaking change, but we'll need an ack from the @PowerShell/powershell-committee before proceeding.

mklement0 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Breaking-Change breaking change that may affect users Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Sep 6, 2017
@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Sep 6, 2017

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee can see how this can be useful and the current documented behavior is an edge case that isn't likely used so accepting this breaking change is approved

mklement0 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Sep 6, 2017
@lzybkr Jason Shirk (lzybkr) removed the Breaking-Change breaking change that may affect users label Sep 6, 2017
@lzybkr

Jason Shirk (lzybkr) commented Sep 6, 2017

Copy link
Copy Markdown
Contributor

The suggested behavior for negative count should be a different PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Sep 7, 2017

Copy link
Copy Markdown
Collaborator Author

Michael Klement (@mklement0) Feel free to open Issue for the negative count enhancement.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mklement0 Michael Klement (mklement0) mentioned this pull request Sep 7, 2017
Enhance the -split operator with negative maximum token counts to split from the end #4765
Closed
@mklement0

Michael Klement (mklement0) commented Sep 7, 2017

Copy link
Copy Markdown
Contributor

Ilya (@iSazonov): Done - see #4765.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Sep 8, 2017

Copy link
Copy Markdown
Collaborator Author

Jason Shirk (@lzybkr) Is the PR ready to merge?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov Ilya (iSazonov) added the Documentation Needed in this repo Documentation is needed in this repo label Sep 8, 2017
@lzybkr
Jason Shirk (lzybkr) merged commit fc9d798 into PowerShell:master Sep 8, 2017
@iSazonov

Ilya (iSazonov) commented Sep 8, 2017

Copy link
Copy Markdown
Collaborator Author

Jason Shirk (@lzybkr) Michael Klement (@mklement0) Thanks for great discussion!

mklement0 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov
Ilya (iSazonov) deleted the fix-split branch September 8, 2017 16:26
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Sep 8, 2017

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Great test additions! Thanks!

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joeyaiello Joey Aiello (joeyaiello) mentioned this pull request Oct 15, 2018
Docs needed for 'Enable use 'Singleline,Multiline' option in split operator' MicrosoftDocs/PowerShell-Docs#3087
Closed
@joeyaiello Joey Aiello (joeyaiello) removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@iSazonov @lzybkr
Enable use 'Singleline,Multiline' option in split operator (PowerShel…
61dc618
…l#4721)

Fix PowerShell#4712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
3 more reviewers
@mklement0 Michael Klement (mklement0) mklement0 left review comments
@lzybkr Jason Shirk (lzybkr) lzybkr approved these changes
@vors sergei (vors) vors approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@lzybkr Jason Shirk (lzybkr)

Labels

Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@iSazonov @lzybkr @SteveL-MSFT @mklement0 @daxian-dbw @vors @joeyaiello @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.