Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mauke
Copy link
Contributor

@mauke mauke commented Mar 2, 2025

This code used to silently accept \g{123trailing garbage} as long as it started with a valid number.

Fixes #23050.


  • This set of changes requires a perldelta entry, and it is included.

This code used to silently accept \g{123trailing garbage} as long as it
started with a valid number.

Fixes Perl#23050.
@@ -220,6 +220,8 @@ my @death =
'/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/',
'/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/',
'/\g{-abc}/' => 'Group name must start with a non-digit word character {#} m/\g{-{#}abc}/',
'/\g{1-1}/' => 'Sequence \g{... not terminated {#} m/\g{1{#}-1}/',
Copy link
Contributor

Choose a reason for hiding this comment

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

To a human, it is obvious that this is terminated; just syntactically invalid. The parser can be forgiven for not being able to detect that. But it is unfortunate that the existing diagnostic doesn't give that as a possibility. You have to go to perldiag to find that a syntax error is a possibility, We likely can't change existing diagnostics, but this is a new error, and so a clearer error message could be devised.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following the example of named backreferences:

$ perl -e '/\g{foo-bar}/'
Sequence \g{... not terminated in regex; marked by <-- HERE in m/\g{foo <-- HERE -bar}/ at -e line 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's understandable, and maybe it isn't for this PR, but I believe new warning instances shouldn't be bound by inadequacies in previous instances.

@mauke mauke merged commit 8c5e6c3 into Perl:blead Mar 4, 2025
@mauke mauke deleted the fix-23050-g-syntax-check branch March 4, 2025 19: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.

regex \g{...} syntax is missing error checks
2 participants