Perl::Critic::Policy::RegularExpressions::RequireDefault

CPAN version stability-stable Build Status Coverage Status License: Artistic-2.0

NAME

Perl::Critic::Policy::RegularExpressions::RequireDefault - Always use the /a or /aa modifier with regular expressions.

VERSION

This documentation describes version 2.01

AFFILIATION

This policy has no affiliation

DESCRIPTION

This policy aims to help enforce Perl’s protective measures against security vulnerabilities related to Unicode, such as:

The /a and /aa modifiers standing for ASCII-restrict or ASCII-safe, provides protection for applications that do not need to be exposed to all of Unicode and possible security issues with Unicode.

/a causes the sequences \d, \s, \w, and the Posix character classes to match only in the ASCII range. Meaning:

The policy also supports the pragma:

use re '/a';

and:

use re '/aa';

Which mean it will not evaluate the regular expressions any further:

use re '/a';
my $letters =~ m/[A-Za-z0-9_]*/;   # ok

Do note that the /a and /aa modifiers require Perl 5.14, so by using the recommended modifiers you indirectly introduce a requirement for Perl 5.14.

This policy is inspired by Perl::Critic::Policy::RegularExpressions::RequireExtendedFormatting and many implementation details was lifted from this particular distribution.

CONFIGURATION AND ENVIRONMENT

The policy has a single configuration parameter: strict. The default is disabled (0).

The policy, if enabled, allow for both 'a' and 'aa', if strict however is enabled, 'a' will trigger a violation and 'aa' will not.

Example configuration:

[RegularExpressions::RequireDefault]
strict = 1

Do note that the policy also evaluates if the pragmas are enabled, meaning: use re 'a'; will trigger a violation and use re 'a'; will not if the policy is configured for strict evaluation.

INCOMPATIBILITIES

This distribution holds no known incompatibilities at this time, please see “DEPENDENCIES AND REQUIREMENTS” for details on version requirements.

BUGS AND LIMITATIONS

This distribution holds no other known limitations or bugs at this time, please refer to the the issue listing on GitHub for more up to date information.

BUG REPORTING

Please report bugs via GitHub.

TEST AND QUALITY

This distribution aims to adhere to the Perl::Critic::Policy standards and Perl best practices and recommendations.

DEPENDENCIES AND REQUIREMENTS

This distribution requires:

Please see the listing in the file: cpanfile, included with the distribution for a complete listing and description for configuration, test and development.

TODO

Ideas and suggestions for improvements and new features are listed in GitHub and are marked as enhancement.

SEE ALSO

MOTIVATION

The motivation for this Perl::Critic policy came from a tweet by @joel

| Perl folk: Looking for a PR challenge task? Check for \d in regexes
| that really should be [0-9] or should have the /a regex modifier.
| Perl is multinational by default! #TPCiSLC

AUTHOR

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Perl::Critic::Policy::RegularExpressions::RequireDefault is (C) by jonasbn 2018-2019

Perl::Critic::Policy::RegularExpressions::RequireDefault is released under the Artistic License 2.0

Please see the LICENSE file included with the distribution of this module