]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Do some rudimentary error checking.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 9 Jul 2021 19:32:19 +0000 (13:32 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 15 Jul 2021 16:35:54 +0000 (10:35 -0600)
source/base/data_out_base.cc

index 83fb060ed5c177c1937f542ff7e721b74220baef..0eefce3224d6f2c1bed1f937a76073fd333f7bb8 100644 (file)
@@ -5462,6 +5462,17 @@ namespace DataOutBase
   {
     AssertThrow(out, ExcIO());
 
+    // If the user provided physical units, make sure that they don't contain
+    // quote characters as this would make the VTU file invalid XML and
+    // probably lead to all sorts of difficult error messages. Other than that,
+    // trust the user that whatever they provide makes sense somehow.
+    for (const auto unit : flags.physical_units)
+      Assert(
+        unit.second.find('\"') == std::string::npos,
+        ExcMessage(
+          "A physical unit you provided, <" + unit.second +
+          ">, contained a quotation mark character. This is not allowed."));
+
 #ifndef DEAL_II_WITH_MPI
     // verify that there are indeed patches to be written out. most of the
     // times, people just forget to call build_patches when there are no
@@ -5709,14 +5720,14 @@ namespace DataOutBase
             AssertThrow((last_component + 1 - first_component <= 9),
                         ExcMessage(
                           "Can't declare a tensor with more than 9 components "
-                          "in VTK"));
+                          "in VTK/VTU format."));
           }
         else
           {
             AssertThrow((last_component + 1 - first_component <= 3),
                         ExcMessage(
                           "Can't declare a vector with more than 3 components "
-                          "in VTK"));
+                          "in VTK/VTU format."));
           }
 
         // mark these components as already written:
@@ -5891,6 +5902,17 @@ namespace DataOutBase
   {
     AssertThrow(out, ExcIO());
 
+    // If the user provided physical units, make sure that they don't contain
+    // quote characters as this would make the VTU file invalid XML and
+    // probably lead to all sorts of difficult error messages. Other than that,
+    // trust the user that whatever they provide makes sense somehow.
+    for (const auto unit : flags.physical_units)
+      Assert(
+        unit.second.find('\"') == std::string::npos,
+        ExcMessage(
+          "A physical unit you provided, <" + unit.second +
+          ">, contained a quotation mark character. This is not allowed."));
+
     const unsigned int n_data_sets = data_names.size();
 
     out << "<?xml version=\"1.0\"?>\n";

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.