Skip to content

Alternate: Fix IndexOutOfRangeException in GenerateRender - #1050

Closed
Carl Morris (msftrncs) wants to merge 2 commits into
PowerShell:masterfrom
msftrncs:InCaseOfMissingEOS
Closed

Carl Morris (msftrncs) wants to merge 2 commits into
PowerShell:masterfrom
msftrncs:InCaseOfMissingEOS

Conversation

@msftrncs

Copy link
Copy Markdown
Collaborator

Offering slightly different, but really the same, fix for #911, along with a test, but with less explanation.

/cc: Dongbo Wang (@daxian-dbw)

@msftrncs Carl Morris (msftrncs) changed the title Alternate: Fix IndexOutOfRangeException Alternate: Fix IndexOutOfRangeException in GenerateRender Sep 16, 2019
Insure that the next token on the token stack is checked for being the
final token so that in the rare event that the EOS token is missing,
rendering doesn't attempt to access non-existant tokens.

Optimization of redundant evaluation in the subject `while` loop.

Optimization of check for last token in current state.

Fixes PowerShell#911
Test for Render Exception on missing EOS token when a nested token
is also present.
@daxian-dbw

Copy link
Copy Markdown
Member

I like your changes better. I will update mine to be the same as yours with additional comments and one more test to cover the NullReferenceException.

@msftrncs

Copy link
Copy Markdown
Collaborator Author

Interestingly, the NullReferenceException occurs only in beta5, due to #989.

@daxian-dbw

Copy link
Copy Markdown
Member

Carl Morris (@msftrncs) Yes :)

@msftrncs

Copy link
Copy Markdown
Collaborator Author

I almost submitted #989 with a the break in it, but thought the EOS would always be there. I'm mentioning this for reference, as I should have added break when adding the while, because token is made null, and then without a break token is used in a reference. My gut said the break was needed, I just couldn't see why immediately. 😃

@daxian-dbw

Copy link
Copy Markdown
Member

No worries at all. I didn't realize the stop early design for parsing NamedBlock until looking at this issue.
I looked into PowerShell code to see if process xxxx xxx, begin xxxx ... and end xxx ... should be fixed to generate tokens in a more expected/friendly way.
It doesn't look like a simple change to make it happen. The design is to stop parsing when process, begin and end don't end up with a valid NamedBlock, so tokenizing terminates in the middle as by design in those cases.
Fixing it in PSReadLine makes more sense.

@daxian-dbw

Copy link
Copy Markdown
Member

Carl Morris (@msftrncs) Do you mind taking a look at my updates to #1049?
I took your changes and added additional comments and changed the tests a bit.
I didn't update your branch directly only because it's easier to work in my branch :)

@daxian-dbw

Copy link
Copy Markdown
Member

Also, I invited you as a contributor to the PSReadLine repo, would you like to accept it? 😄

@daxian-dbw

Copy link
Copy Markdown
Member

Close this one as #1049 has been merged. Thanks Carl Morris (@msftrncs)!

@msftrncs
Carl Morris (msftrncs) deleted the InCaseOfMissingEOS branch September 17, 2019 04:26
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

Successfully merging this pull request may close these issues.

2 participants