File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -144,6 +144,8 @@ namespace osmium {
144144 * Returns a pointer to next character that needs to be consumed.
145145 */
146146 inline void opl_parse_escaped (const char ** data, std::string& result) {
147+ assert (data);
148+ assert (*data);
147149 const char * s = *data;
148150 uint32_t value = 0 ;
149151 const int max_length = sizeof (value) * 2 /* hex chars per byte */ ;
@@ -154,7 +156,11 @@ namespace osmium {
154156 }
155157 if (*s == ' %' ) {
156158 ++s;
157- append_codepoint_as_utf8 (value, std::back_inserter (result));
159+ if (value == 0 ) {
160+ result += ' %' ;
161+ } else {
162+ append_codepoint_as_utf8 (value, std::back_inserter (result));
163+ }
158164 *data = s;
159165 return ;
160166 }
@@ -182,6 +188,8 @@ namespace osmium {
182188 * Returns a pointer to next character that needs to be consumed.
183189 */
184190 inline void opl_parse_string (const char ** data, std::string& result) {
191+ assert (data);
192+ assert (*data);
185193 const char * s = *data;
186194 while (true ) {
187195 if (*s == ' \0 ' || *s == ' ' || *s == ' \t ' || *s == ' ,' || *s == ' =' ) {
Original file line number Diff line number Diff line change @@ -203,6 +203,7 @@ namespace osmium {
203203
204204 inline void append_utf8_encoded_string (std::string& out, const char * data) {
205205 static const char * lookup_hex = " 0123456789abcdef" ;
206+ assert (data);
206207 const char * end_ptr = data + std::strlen (data);
207208
208209 while (data != end_ptr) {
@@ -236,6 +237,7 @@ namespace osmium {
236237 }
237238
238239 inline void append_xml_encoded_string (std::string& out, const char * data) {
240+ assert (data);
239241 for (; *data != ' \0 ' ; ++data) {
240242 switch (*data) {
241243 case ' &' : out += " &" ; break ;
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ TEST_CASE("Parse OPL: parse escaped") {
104104 const char * e = s + std::strlen (s);
105105 oid::opl_parse_escaped (&s, result);
106106 REQUIRE (result.size () == 1 );
107- REQUIRE (result[0 ] == ' \0 ' );
107+ REQUIRE (result[0 ] == ' % ' );
108108 REQUIRE (s == e);
109109 }
110110
You can’t perform that action at this time.
0 commit comments