diff --git a/src/tawashi_implem/num_conv.hpp b/src/tawashi_implem/num_conv.hpp
new file mode 100644
index 0000000..a3f1357
--- /dev/null
+++ b/src/tawashi_implem/num_conv.hpp
@@ -0,0 +1,34 @@
+/* Copyright 2017, Michele Santullo
+ * This file is part of "tawashi".
+ *
+ * "tawashi" 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.
+ *
+ * "tawashi" 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 "tawashi". If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+namespace tawashi {
+ template
+ inline bool seems_valid_number (const boost::string_ref& parValue) {
+ const std::size_t skip_sign = (sprout::is_signed::value and not parValue.empty() and parValue[0] == '-' ? 1 : 0);
+ for (std::size_t z = skip_sign; z < parValue.size(); ++z) {
+ const char c = parValue[z];
+ if (c < '0' or c > '9')
+ return false;
+ }
+ return parValue.size() - skip_sign <= dhandy::tags::dec::count_digits_bt(sprout::numeric_limits::max());
+ }
+} //namespace tawashi
diff --git a/src/tawashi_implem/response.cpp b/src/tawashi_implem/response.cpp
index d3d65c6..f832ee4 100644
--- a/src/tawashi_implem/response.cpp
+++ b/src/tawashi_implem/response.cpp
@@ -24,6 +24,7 @@
#include "pathname/pathname.hpp"
#include "list_highlight_langs.hpp"
#include "cgi_env.hpp"
+#include "num_conv.hpp"
#include
#include
#include
@@ -126,7 +127,7 @@ namespace tawashi {
oss << ':' << port;
}
}
- else if (not host_port.empty()) {
+ else if (not host_port.empty() and seems_valid_number(host_port)) {
oss << ':' << host_port;
}
}