Skip to content

Commit 03aeae8

Browse files
committed
fix for invalid utf8 strings (included third party utf8 lib)
1 parent 69a6883 commit 03aeae8

File tree

5 files changed

+700
-14
lines changed

5 files changed

+700
-14
lines changed

timers.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ void TimersResponder::reply(std::ostream& out, cxxtools::http::Request& request,
88
showTimers(out, request, reply);
99
} else if ( request.method() == "DELETE" ) {
1010
deleteTimer(out, request, reply);
11-
} else if ( request.method() == "POST" ) {
11+
} else if ( request.method() == "POST" || request.method() == "PUT" ) {
1212
createTimer(out, request, reply);
1313
} else {
14-
reply.httpReturn(501, "Only GET, DELETE and POST methods are supported.");
14+
reply.httpReturn(501, "Only GET, DELETE, POST and PUT methods are supported.");
1515
}
1616
}
1717

1818
void TimersResponder::createTimer(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
1919
{
20-
esyslog("restulfapi: /%s/", request.bodyStr().c_str());
21-
20+
esyslog("restfulapi: /%s/", (const char*)request.bodyStr().c_str());
21+
/*
2222
cxxtools::QueryParams q;
2323
if ( request.method() != "POST" && request.method() != "PUT" ) {
2424
reply.httpReturn(501, "ONly POST and PUT methods are supported.");
@@ -88,7 +88,7 @@ void TimersResponder::createTimer(std::ostream& out, cxxtools::http::Request& re
8888
esyslog("restfulapi: successfully added timer");
8989
}
9090
}
91-
}
91+
}*/
9292
}
9393

9494
void TimersResponder::deleteTimer(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)

tools.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ std::string UTF8Encode(cxxtools::String str)
99
cxxtools::String UTF8Decode(std::string str)
1010
{
1111
static cxxtools::Utf8Codec utf8;
12-
return utf8.decode(str);
12+
std::string temp;
13+
utf8::replace_invalid(str.begin(), str.end(), back_inserter(temp));
14+
return utf8.decode(temp);
1315
}
1416

1517
void write(std::ostream* out, std::string str)
@@ -45,18 +47,14 @@ std::string encodeToXml( const std::string &sSrc )
4547
case '\'': sRet << "&apos;"; break;
4648

4749
default:
48-
/*if ( c<32 || c>127 )
49-
{
50-
sRet << "&#" << (unsigned int)c << ";";
51-
}
52-
else
53-
{*/
5450
sRet << c;
55-
//}
5651
}
5752
}
5853

59-
return sRet.str();
54+
std::string res = sRet.str();
55+
std::string converted;
56+
utf8::replace_invalid(res.begin(), res.end(), back_inserter(converted));
57+
return converted;
6058
}
6159

6260
std::string getRestParams(std::string service, std::string url)

tools.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66
#include <cxxtools/string.h>
77
#include <cxxtools/utf8codec.h>
8+
#include "utf8_checked.h"
89

910
// General Helper Methods
1011
cxxtools::String UTF8Decode(std::string str);

0 commit comments

Comments
 (0)