gbranden pushed a commit to branch master
in repository groff.
commit 775ffc9d72be322d69d4158b5aa9e0980f54b43f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 22 16:38:25 2026 -0500
[troff]: Ignore `substring` if indices invalid.
* src/roff/troff/input.cpp (substring_request): Ignore request if both
the "start" and "end" indices are out of range.
* src/roff/troff/request.h (class macro): Drop declaration of `friend`
function `substring_request()`.
* doc/groff.texi.in (Strings) <substring>:
* man/groff_diff.7.man (New requests) <substring>: Document it.
* src/roff/groff/tests/substring-request-on-invalid-range-is-no-op.sh:
Test new behavior.
---
ChangeLog | 14 ++++++++++++++
doc/groff.texi.in | 11 +++++++++++
man/groff_diff.7.man | 8 ++++++++
.../tests/substring-request-on-invalid-range-is-no-op.sh | 14 +++++++-------
src/roff/troff/input.cpp | 7 ++++++-
src/roff/troff/request.h | 1 -
6 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ff44f7d7e..9fb8a61a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2026-03-21 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/input.cpp (substring_request): Ignore request
+ if both the "start" and "end" indices are out of range.
+ * src/roff/troff/request.h (class macro): Drop declaration of
+ `friend` function `substring_request()`.
+
+ * doc/groff.texi.in (Strings) <substring>:
+ * man/groff_diff.7.man (New requests) <substring>: Document it.
+
+ * src/roff/groff/tests/\
+ substring-request-on-invalid-range-is-no-op.sh: Test new
+ behavior.
+
2026-03-21 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (substring_request): Slightly
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index ed02ea864..b66339bd4 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -15394,6 +15394,17 @@ Negative indices count backward from the end of the
string:@:
the last element has index@tie{}@minus{}1,
the element before the last has index@tie{}@minus{}2,
and so on.
+If both
+@var{start}
+and
+@var{end}
+lie outside the string,
+GNU
+@command{troff} @c GNU
+ignores the request.@footnote{It also
+emits a warning in category
+@samp{range}.
+@xref{Warnings}.}
@Example
.ds xxx abcdefgh
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index a1f07c71e..1a0f7fd4a 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -4474,6 +4474,14 @@ the last element has index\~\-1,
the element before the last has index\~\-2,
and so on.
.
+If both
+.I start
+and
+.I end
+lie outside the string,
+GNU
+.I troff \" GNU
+ignores the request.
.
.
.IP
diff --git
a/src/roff/groff/tests/substring-request-on-invalid-range-is-no-op.sh
b/src/roff/groff/tests/substring-request-on-invalid-range-is-no-op.sh
index bf92d5f2d..30fc92930 100755
--- a/src/roff/groff/tests/substring-request-on-invalid-range-is-no-op.sh
+++ b/src/roff/groff/tests/substring-request-on-invalid-range-is-no-op.sh
@@ -57,13 +57,13 @@ echo "verifying that 'substring' request with out-of-range
index" \
"arguments (ending index negative) performs no operation" >&2
echo "$output" | grep -qx "def" || wail
-#echo "verifying that 'substring' request with out-of-range index" \
-# "arguments (both indices positive) performs no operation" >&2
-#echo "$output" | grep -qx "ghi" || wail
-#
-#echo "verifying that 'substring' request with out-of-range index" \
-# "arguments (both indices negative) performs no operation" >&2
-#echo "$output" | grep -qx "jkl" || wail
+echo "verifying that 'substring' request with out-of-range index" \
+ "arguments (both indices positive) performs no operation" >&2
+echo "$output" | grep -qx "ghi" || wail
+
+echo "verifying that 'substring' request with out-of-range index" \
+ "arguments (both indices negative) performs no operation" >&2
+echo "$output" | grep -qx "jkl" || wail
test -z "$fail"
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 6da2bad13..799aa8c33 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5836,13 +5836,18 @@ void substring_request()
}
if ((start >= operable_length) || (end < 0)) {
warning(WARN_RANGE,
- "start and end index of substring out of range");
+ "ignoring substring request; start and end index"
+ " out of range");
+ // XXX: If we restore this functionality, it might be better
+ // done with a `macro` class member function called from here.
+#if 0
len = m->len = 0;
if (m->p != 0 /* nullptr */) {
if (--(m->p->count) <= 0)
delete m->p;
m->p = 0 /* nullptr */;
}
+#endif
skip_line();
return;
}
diff --git a/src/roff/troff/request.h b/src/roff/troff/request.h
index 5a4d007d5..3eb024464 100644
--- a/src/roff/troff/request.h
+++ b/src/roff/troff/request.h
@@ -75,7 +75,6 @@ public:
void dump();
void json_dump();
friend class string_iterator;
- friend void substring_request();
friend bool operator==(const macro &, const macro &);
};
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit