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

NullReferenceException when parsing regular expression #39077

Closed
abelbraaksma opened this issue Jul 10, 2020 · 3 comments
Closed

NullReferenceException when parsing regular expression #39077

abelbraaksma opened this issue Jul 10, 2020 · 3 comments
Labels
area-System.Text.RegularExpressions untriaged New issue has not been triaged by the area owner

Comments

@abelbraaksma
Copy link
Contributor

abelbraaksma commented Jul 10, 2020

Description

The following code raises an NRE:

Regex("(?(?x)yesno)")
// System.NullReferenceException: Object reference not set to an instance of an object.

Expected: a normal ArgumentException as any invalid regex raises that. The error in this regex is that the conditional part missing an alternation character |. Correct would be: ?(?x)yes|no)

Note that (?(x)yesno) compiles fine, so there's an argument to be made for the above to compile fine too, as technically they should be equivalent (a conditional alternation with only a true-part).

(found while working on #38872, but not related to that issue per se)

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.RegularExpressions untriaged New issue has not been triaged by the area owner labels Jul 10, 2020
@ghost
Copy link

ghost commented Jul 10, 2020

Tagging subscribers to this area: @eerhardt, @pgovind
Notify danmosemsft if you want to be subscribed.

@stephentoub
Copy link
Member

stephentoub commented Jul 10, 2020

This was fixed in .NET Core several versions ago. It now produces:
"System.Text.RegularExpressions.RegexParseException: Invalid pattern '(?(?x)yesno)' at offset 5. Unrecognized grouping construct."

@abelbraaksma
Copy link
Contributor Author

abelbraaksma commented Jul 10, 2020

My bad, I accidentally tested 4.8 only,which clearly didn't get that fix. Glad it's solved!

Btw, I don't think it should be an error, but I assume that's decided and a given now.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.RegularExpressions untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants