From 48a1078a853197466cbbc134634a8673d801c8a1 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 17 Jun 2018 10:20:45 +0200 Subject: Sanitize strings in the xml output. --- test/dgunit.h | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/test/dgunit.h b/test/dgunit.h index 358c70d..6717310 100644 --- a/test/dgunit.h +++ b/test/dgunit.h @@ -120,13 +120,13 @@ public: for(auto test : failed_tests) { out << " \n"; - out << " " << test.func << "\n"; + out << " " << sanitize(test.func) << "\n"; out << " Assertion\n"; out << " \n"; - out << " " << test.file << "\n"; + out << " " << sanitize(test.file) << "\n"; out << " " << test.line << "\n"; out << " \n"; - out << " " << test.msg << "\n"; + out << " " << sanitize(test.msg) << "\n"; out << " \n"; } out << " \n"; @@ -134,7 +134,7 @@ public: for(auto test : successful_tests) { out << " \n"; - out << " " << test.func << "\n"; + out << " " << sanitize(test.func) << "\n"; out << " \n"; } @@ -204,6 +204,33 @@ protected: assert_equal(expected, value, __FILE__, __LINE__) private: + static std::string sanitize(const std::string& input) + { + std::string output; + for(auto c : input) + { + switch(c) + { + case '"': + output += """; + break; + case '&': + output += "&"; + break; + case '<': + output += "<"; + break; + case '>': + output += ">"; + break; + default: + output += c; + break; + } + } + return output; + } + static DGUnit* suite_list; DGUnit* next_unit{nullptr}; std::vector, const char*>> tests; -- cgit v1.2.3