gbranden pushed a commit to branch master
in repository groff.

commit fa07c652ef69d281285ca5b85c25cc9494960f12
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Nov 22 05:46:18 2026 -0600

    [soelim]: Add warning diagnostic.
    
    * src/preproc/soelim/soelim.cpp (do_so): Warn when an invalid escape
      sequence occurs in the argument after the ".so" token, and identify
      the offending sequence.
    
    * src/preproc/soelim/tests/warning-invalid-escape-sequence.sh: New file;
      test it.
    
    * src/preproc/soelim/soelim.am: Update `soelim_TESTS` to run test.
    
    Exhibit:
    
    $ printf '.so foo\\bar\n' | ./build/soelim
    .lf 1 "-
    ./build/soelim:<standard input>:2: warning: not sourcing invalid file name 
containing invalid sequence "\b"
    .so foo\bar
---
 ChangeLog                                          | 13 +++++++++++
 src/preproc/soelim/soelim.am                       |  1 +
 src/preproc/soelim/soelim.cpp                      | 11 ++++++++-
 .../tests/warning-invalid-escape-sequence.sh       | 26 ++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 9a00d288a..2c592feff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2026-11-22  G. Branden Robinson <[email protected]>
+
+       [soelim]: Add warning diagnostic.
+
+       * src/preproc/soelim/soelim.cpp (do_so): Warn when an invalid
+       escape sequence occurs in the argument after the ".so" token,
+       and identify the offending sequence.
+
+       * src/preproc/soelim/tests/warning-invalid-escape-sequence.sh:
+       New file; test it.
+       * src/preproc/soelim/soelim.am: Update `soelim_TESTS` to run
+       test.
+
 2026-11-22  G. Branden Robinson <[email protected]>
 
        [grotty]: Recognize "TERM=dumb".
diff --git a/src/preproc/soelim/soelim.am b/src/preproc/soelim/soelim.am
index 98b151663..ec815c1d6 100644
--- a/src/preproc/soelim/soelim.am
+++ b/src/preproc/soelim/soelim.am
@@ -25,6 +25,7 @@ soelim_TESTS = \
   src/preproc/soelim/tests/leading-quote-before-file-name-works.sh \
   src/preproc/soelim/tests/passes-through-input-with-eighth-bit-set.sh \
   src/preproc/soelim/tests/warning-escaped-space-gets-lineno-right.sh \
+  src/preproc/soelim/tests/warning-invalid-escape-sequence.sh \
   src/preproc/soelim/tests/produces-accurate-lf-requests.sh \
   src/preproc/soelim/tests/smoke-test.sh \
   src/preproc/soelim/tests/space-in-argument-works.sh \
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index 1b00c9bde..7f78f7275 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -159,6 +159,7 @@ static void do_so(const char *line)
   string filename;
   bool is_filename_valid = true;
   const char *q = p;
+  char invalid_char = '\0';
   if ('"' == *q)
     q++;
   for (; is_filename_valid && (*q != '\0') && (*q != '\n'); q++)
@@ -181,13 +182,21 @@ static void do_so(const char *line)
        // is_filename_valid = false; // or fall through
        break;
       default:
+       invalid_char = *q;
        is_filename_valid = false;
        break;
       }
     }
     else
       filename += char(*q);
-  if (is_filename_valid && (filename.length() > 0)) {
+  if (!is_filename_valid) {
+    // Temporarily decrement the line counter as above.
+    current_lineno--;
+    warning("not sourcing invalid file name"
+           " containing invalid sequence \"\\%1\"", invalid_char);
+    current_lineno++;
+  }
+  else if ((filename.length() > 0)) {
     filename += '\0';
     const char *fn = current_filename;
     int ln = current_lineno;
diff --git a/src/preproc/soelim/tests/warning-invalid-escape-sequence.sh 
b/src/preproc/soelim/tests/warning-invalid-escape-sequence.sh
new file mode 100755
index 000000000..8711397d0
--- /dev/null
+++ b/src/preproc/soelim/tests/warning-invalid-escape-sequence.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# This file is part of groff, the GNU roff typesetting system.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+soelim="${abs_top_builddir:-.}/soelim"
+
+# Invalid escape sequences should produce a warning
+
+warning=$(printf '.so foo\\bar\n' | "$soelim" 2>&1 > /dev/null)
+printf '%s\n' "$warning"
+printf '%s\n' "$warning" | grep -q ':1: warning:'
+
+# vim:set autoindent expandtab shiftwidth=4 tabstop=4 textwidth=72:

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to