mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Input framework now accepts escaped ascii values as input.
I managed to completely forget to add unescaping to the input framework - this should fix it. It now works with the exact same escaping that is used by the writers (\x##). Includes one testcase that seems to work - everything else still passes.
This commit is contained in:
parent
336990e234
commit
8e453663dd
3 changed files with 58 additions and 15 deletions
|
@ -438,6 +438,8 @@ bool Ascii::DoUpdate()
|
|||
if ( ! getline(splitstream, s, separator[0]) )
|
||||
break;
|
||||
|
||||
s = get_unescaped_string(s);
|
||||
|
||||
stringfields[pos] = s;
|
||||
pos++;
|
||||
}
|
||||
|
|
44
src/util.cc
44
src/util.cc
|
@ -42,6 +42,46 @@
|
|||
#include "Net.h"
|
||||
#include "Reporter.h"
|
||||
|
||||
/**
|
||||
* Takes a string, unescapes all characters that are escaped as hex codes
|
||||
* (\x##) and turns them into the equivalent ascii-codes. Returns a string
|
||||
* containing no escaped values
|
||||
*
|
||||
* @param str string to unescape
|
||||
* @return A str::string without escaped characters.
|
||||
*/
|
||||
std::string get_unescaped_string(const std::string& str)
|
||||
{
|
||||
char* buf = new char [str.length() + 1]; // it will at most have the same length as str.
|
||||
char* bufpos = buf;
|
||||
size_t pos = 0;
|
||||
|
||||
while ( pos < str.length() )
|
||||
{
|
||||
if ( str[pos] == '\\' && str[pos+1] == 'x' &&
|
||||
isxdigit(str[pos+2]) && isxdigit(str[pos+3]) )
|
||||
{
|
||||
*bufpos = (decode_hex(str[pos+2]) << 4) +
|
||||
decode_hex(str[pos+3]);
|
||||
|
||||
pos += 4;
|
||||
bufpos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bufpos = str[pos];
|
||||
bufpos++;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
*bufpos = 0;
|
||||
|
||||
string outstring (buf, bufpos - buf);
|
||||
delete [] buf;
|
||||
return outstring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a string, escapes characters into equivalent hex codes (\x##), and
|
||||
* returns a string containing all escaped values.
|
||||
|
@ -53,7 +93,7 @@
|
|||
* @return A std::string containing a list of escaped hex values of the form
|
||||
* \x## */
|
||||
std::string get_escaped_string(const std::string& str, bool escape_all)
|
||||
{
|
||||
{
|
||||
char tbuf[16];
|
||||
string esc = "";
|
||||
|
||||
|
@ -71,7 +111,7 @@ std::string get_escaped_string(const std::string& str, bool escape_all)
|
|||
}
|
||||
|
||||
return esc;
|
||||
}
|
||||
}
|
||||
|
||||
char* copy_string(const char* s)
|
||||
{
|
||||
|
|
|
@ -90,6 +90,7 @@ void delete_each(T* t)
|
|||
delete *it;
|
||||
}
|
||||
|
||||
std::string get_unescaped_string(const std::string& str);
|
||||
std::string get_escaped_string(const std::string& str, bool escape_all);
|
||||
|
||||
extern char* copy_string(const char* s);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue