From 7c302e0eb45f52bdcc507de1226be39c15032859 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 9 Jul 2021 13:32:19 -0600 Subject: [PATCH] Do some rudimentary error checking. --- source/base/data_out_base.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 83fb060ed5..0eefce3224 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -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 << "\n"; -- 2.39.5