Don't use non-POSIX \+ syntax in BREs.

It's implementation-defined whether \+ behaves like literal + or like
\{1,\}.  (The same applies to \? and \|; I didn't find uses of those.)
As it happens, OpenBSD treats it as literal '+'.

Found it through a failure of html-device-smoke-test.sh.

See <https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap09.html#tag_09_03_02>.
This commit is contained in:
Lennart Jablonka 2025-03-30 22:23:58 +00:00 committed by G. Branden Robinson
parent 8d1221a375
commit 7ae45a1d4c
6 changed files with 29 additions and 9 deletions

View File

@ -1,3 +1,23 @@
2025-03-30 Lennart Jablonka <humm@ljabl.com>
Don't use non-POSIX syntax `\+` in BREs.
It's implementation-defined whether \+ behaves like literal + or
like \{1,\}. (The same applies to \? and \|; I didn't find uses
of those.) As it happens, OpenBSD treats it as literal '+'.
* m4/groff.m4 (GROFF_PAGE):
* makevarescape.sed:
* src/libs/libgroff/make-uniuni:
* src/roff/groff/tests/html-device-smoke-test.sh:
* src/utils/afmtodit/make-afmtodit-tables: Use more portable
sed(1) and grep(1) syntax.
Found through a failure of html-device-smoke-test.sh.
See <https://pubs.opengroup.org/onlinepubs/\
9799919799.2024edition/basedefs/V1_chap09.html#tag_09_03_02>.
2025-04-11 G. Branden Robinson <g.branden.robinson@gmail.com>
[font]: Update and parallelize `DESC` file generation.

View File

@ -942,7 +942,7 @@ AC_DEFUN([GROFF_PAGE], [
papersize=/etc/papersize
if test -z "$PAGE" && test -r "$papersize"
then
sedexpr='s/#.*//;s/[ \t]\+/ /;s/ \+$//;s/^ \+//;/^$/d;p'
sedexpr='s/#.*//;s/[ \t]\{1,\}/ /;s/ *$//;s/^ *//;/^$/d;p'
PAGE=`sed -n "$sedexpr" "$papersize"`
test -n "$PAGE" && whence=$papersize
fi
@ -969,10 +969,10 @@ AC_DEFUN([GROFF_PAGE], [
if test -n "$descfile"
then
if grep -q ['^paperlength[ ]\+841890'] "$descfile"
if grep -q ['^paperlength[ ]\{1,\}841890'] "$descfile"
then
PAGE=A4
elif grep -q ['^papersize[ ]\+[aA]4'] "$descfile"
elif grep -q ['^papersize[ ]\{1,\}[aA]4'] "$descfile"
then
PAGE=A4
fi
@ -986,7 +986,7 @@ AC_DEFUN([GROFF_PAGE], [
domains=
if test -r "$resolvconf"
then
sedexpr='s/#.*//;s/[ \t]\+/ /;s/ \+$//;s/^ \+//;/^$/d;
sedexpr='s/#.*//;s/[ \t]\{1,\}/ /;s/ *$//;s/^ *//;/^$/d;
/^\(domain\|search\)/!d;s/\(domain\|search\) //;p'
domains=`sed -n "$sedexpr" "$resolvconf"`
fi

View File

@ -6,4 +6,4 @@ s/-/\\\\&/g
s/\^/\\\\[ha]/g
s/`/\\\\[ga]/g
s/~/\\\\[ti]/g
s|[^ ]/\+|&\\\\:\\\\%|g
s|[^ ]//*|&\\\\:\\\\%|g

View File

@ -60,7 +60,7 @@ cat $$1 \
cat $$3 \
| sed -e '/#/d' \
-e '/^$/d' \
-e 's/ \+/ /g' \
-e 's/ */ /g' \
-e 's/ *$//' \
-e 's/u//g' \
-e 's/^\([^ ]*\) /\1;/' > $$4

View File

@ -55,7 +55,7 @@ foobar
echo "checking production of inline image for tbl(1) table" >&2
output=$(echo "$input" | "$groff" -t -Thtml)
echo "$output" | grep -q '<img src="grohtml-[0-9]\+-1.png"' || wail
echo "$output" | grep -q '<img src="grohtml-[0-9]\{1,\}-1.png"' || wail
input='.EQ
x sup 2 + y sup 2 = z sup 2
@ -63,7 +63,7 @@ x sup 2 + y sup 2 = z sup 2
echo "checking production of inline image for eqn(1) equation" >&2
output=$(echo "$input" | "$groff" -e -Thtml)
echo "$output" | grep -q '<img src="grohtml-[0-9]\+-2.png"' || wail
echo "$output" | grep -q '<img src="grohtml-[0-9]\{1,\}-2.png"' || wail
cleanup

View File

@ -74,7 +74,7 @@ cat $$1 \
cat $$3 \
| sed -e '/#/d' \
-e '/^$/d' \
-e 's/ \+/ /g' \
-e 's/ */ /g' \
-e 's/ *$//' \
-e 's/u//g' \
-e 's/^\([^ ]*\) /\1;/' > $$4