From 40ff2acdd680942e925cdd3d9e9144de200c5258 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Sat, 17 Jul 2021 19:30:43 +0200
Subject: [PATCH] BUG: word input is too strict (fixes #2160)

- for v2106 restricted the input conversion of string types to disallow
  treating verbatim strings as possible word input.
  However, it was too strict in just allowing quoted strings
  and should have also permitted '$'-sigil variables as well.

- ensure that errors for bad string -> word input conversion
  are raised from within the '>>' read operator. These were
  previously triggered during the stripping process, which
  made error tracing more difficult.
---
 src/OpenFOAM/primitives/strings/word/wordIO.C | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/OpenFOAM/primitives/strings/word/wordIO.C b/src/OpenFOAM/primitives/strings/word/wordIO.C
index 03e46193ca6..060b871d3b7 100644
--- a/src/OpenFOAM/primitives/strings/word/wordIO.C
+++ b/src/OpenFOAM/primitives/strings/word/wordIO.C
@@ -48,15 +48,16 @@ Foam::Istream& Foam::operator>>(Istream& is, word& val)
     {
         val = tok.wordToken();
     }
-    else if (tok.isQuotedString())
+    else if (tok.isQuotedString() || tok.isVariable())
     {
-        // Try a bit harder and convert string to word
-        val = tok.stringToken();
-        const auto oldLen = val.length();
-        string::stripInvalid<word>(val);
+        // Try a bit harder, convert some string types to word
+        // - accept "quoted" or $tag, but not verbatim/expression
+
+        const auto& str = tok.stringToken();
+        val = word::validate(str);
 
         // Flag empty strings and bad chars as an error
-        if (val.empty() || val.length() != oldLen)
+        if (val.empty() || val.length() != str.length())
         {
             FatalIOErrorInFunction(is)
                 << "Empty word or non-word characters "
-- 
GitLab