diff options
author | rillig <rillig@pkgsrc.org> | 2020-05-11 19:52:13 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-05-11 19:52:13 +0000 |
commit | 410abb43017d6e300eb42c21a76cca0086d87a0a (patch) | |
tree | 80e074fec3d33e9b4ea342c3f49a5e391a9b10f9 /regress | |
parent | f4d514e69bbf4d4bf68144cd124029bfed3e26b7 (diff) | |
download | pkgsrc-410abb43017d6e300eb42c21a76cca0086d87a0a.tar.gz |
mk/subst.mk: fix edge case in detection of identity substitutions
In a basic regular expression, a dollar-sign only means end-of-string if
it appears at the end of the pattern, or (at the choice of the
implementation) at the end of a \(...\) subexpression.
This affects the package converters/help2man that uses a regular
expression containing a dollar in a non-final position. This regular
expression had not been detected as an identity substitution even though
it is one.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/infra-unittests/subst.sh | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/regress/infra-unittests/subst.sh b/regress/infra-unittests/subst.sh index 9268740f466..5e25cad971f 100644 --- a/regress/infra-unittests/subst.sh +++ b/regress/infra-unittests/subst.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: subst.sh,v 1.35 2020/05/11 19:17:22 rillig Exp $ +# $NetBSD: subst.sh,v 1.36 2020/05/11 19:52:13 rillig Exp $ # # Tests for mk/subst.mk. # @@ -1219,9 +1219,29 @@ if test_case_begin "identity substitution implementation"; then # See converters/help2man for an example. assert_identity 'yes' -e 's,\$(var),$(var),' - # An unescaped dollar means end-of-line and cannot be part of an - # identity substitution. This may happen, but is clearly a typo. - assert_identity 'no' -e 's,$(var),$(var),' + # POSIX 2004 and 2018 both define in section "9.3.8 BRE Expression + # Anchoring" that a dollar-sign at the end of the string means + # end-of-string. + # + # A dollar-sign followed by \) may or may not be an anchor. + # In all other cases the dollar is an ordinary character. + assert_identity 'yes' -e 's,$(var),$(var),' + + # Since this dollar-sign may or may not be an anchor, treat the + # whole regular expression as not-an-identity. + # + # Since a regular expression with a subexpression must contain + # \( and \), it does not count as an identity substitution anyway, + # which makes the implementation simple. + assert_identity 'no' -e 's,aaa\(aaa$\),aaa\(aaa$\),' + + assert_identity 'yes' -e 's,$a,$a,' + assert_identity 'no' -e 's,a$,a$,' + + # Same for the circumflex. + assert_identity 'yes' -e 's,a^,a^,' + assert_identity 'no' -e 's,^a,^a,' + assert_identity 'no' -e 's,\(^aaa\)aaa,\(^aaa\)aaa,' test_case_end fi |