diff options
-rw-r--r-- | mk/subst.mk | 4 | ||||
-rw-r--r-- | regress/infra-unittests/subst.sh | 25 |
2 files changed, 24 insertions, 5 deletions
diff --git a/mk/subst.mk b/mk/subst.mk index 7ed68940b78..6911dedd82b 100644 --- a/mk/subst.mk +++ b/mk/subst.mk @@ -1,4 +1,4 @@ -# $NetBSD: subst.mk,v 1.78 2020/04/18 12:59:43 rillig Exp $ +# $NetBSD: subst.mk,v 1.79 2020/04/18 15:04:34 rillig Exp $ # # The subst framework replaces text in one or more files in the WRKSRC # directory. Packages can define several ``classes'' of replacements. @@ -128,7 +128,7 @@ SUBST_FILTER_CMD.${class}?= LC_ALL=C ${SED} ${SUBST_SED.${class}} SUBST_VARS.${class}?= # none SUBST_MESSAGE.${class}?= Substituting "${class}" in ${SUBST_FILES.${class}} . for v in ${SUBST_VARS.${class}} -SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[.[\\*^${$}]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g +SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[.[\\*^]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g . endfor . if ${SUBST_SHOW_DIFF.${class}:U${SUBST_SHOW_DIFF}:tl} == yes _SUBST_KEEP.${class}?= LC_ALL=C ${DIFF} -u "$$file" "$$tmpfile" || true diff --git a/regress/infra-unittests/subst.sh b/regress/infra-unittests/subst.sh index d32d62a9084..a52ee9c3c07 100644 --- a/regress/infra-unittests/subst.sh +++ b/regress/infra-unittests/subst.sh @@ -797,17 +797,30 @@ if test_case_begin "SUBST_VARS for variables with regex characters"; then # Ensure that special regex characters like dots and parentheses # may appear in variable names and are properly escaped. + # Variable names containing a dollar are not supported. + # Bmake behaves very surprisingly when a $ is expanded inside a :C + # modifier. Nobody needs this feature anyway, it was just an + # experiment to see whether this would be theoretically possible. + + # Variable names ending with a backslash are not supported. + # The backslash may only occur in the middle of the variable name. + create_file_lines "testcase.mk" \ 'SUBST_CLASSES+= vars' \ 'SUBST_STAGE.vars= pre-configure' \ 'SUBST_FILES.vars= vars.txt' \ - 'SUBST_VARS.vars= VAR...... VAR.abcde VAR.() VAR.<> VAR.[]' \ + 'SUBST_VARS.vars= VAR...... VAR.abcde' \ + 'SUBST_VARS.vars+= VAR.() VAR.<> VAR.[]' \ + 'SUBST_VARS.vars+= VAR.$$x VAR.^ VAR.\x' \ '' \ 'VAR......= dots' \ 'VAR.abcde= letters' \ 'VAR.()= parentheses' \ 'VAR.<>= angle brackets' \ 'VAR.[]= square brackets' \ + 'VAR.$$x= dollar' \ + 'VAR.^= circumflex' \ + 'VAR.\x= backslash' \ '' \ '.include "prepare-subst.mk"' \ '.include "mk/subst.mk"' @@ -816,7 +829,10 @@ if test_case_begin "SUBST_VARS for variables with regex characters"; then "@VAR.abcde@" \ "@VAR.()@" \ "@VAR.<>@" \ - "@VAR.[]@" + "@VAR.[]@" \ + '@VAR.$x@' \ + '@VAR.^@' \ + '@VAR.\x@' run_bmake "testcase.mk" "pre-configure" \ 1> "$tmpdir/stdout" \ @@ -828,7 +844,10 @@ if test_case_begin "SUBST_VARS for variables with regex characters"; then "letters" \ "parentheses" \ "angle brackets" \ - "square brackets" + "square brackets" \ + '@VAR.$x@' \ + 'circumflex' \ + 'backslash' assert_that "stdout" --file-is-lines \ "=> Substituting \"vars\" in vars.txt" assert_that "stderr" --file-is-empty |