mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
tests & fix for 0 length modifier value
This commit is contained in:
parent
e7a4df6180
commit
c4340bae9f
6 changed files with 25 additions and 2 deletions
|
@ -109,6 +109,7 @@ typedef struct
|
|||
psycBool contentLengthFound; ///< is there a length given for this packet?
|
||||
size_t valueParsed; ///< number of bytes parsed from the value so far
|
||||
size_t valueLength; ///< expected length of the value
|
||||
psycBool valueLengthFound; ///< is there a length given for this modifier?
|
||||
} psycParseState;
|
||||
|
||||
/**
|
||||
|
@ -231,6 +232,12 @@ size_t psyc_getParseValueLength (psycParseState *state)
|
|||
return state->valueLength;
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_isParseValueLengthFound (psycParseState *state)
|
||||
{
|
||||
return state->valueLengthFound;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getParseCursor (psycParseState *state)
|
||||
{
|
||||
|
|
|
@ -75,7 +75,7 @@ size_t psyc_getModifierLength (psycModifier *m)
|
|||
m->name.length + 1 + // name\t
|
||||
m->value.length + 1; // value\n
|
||||
|
||||
if (m->flag == PSYC_MODIFIER_NEED_LENGTH && m->value.length) // add length of length if needed
|
||||
if (m->flag == PSYC_MODIFIER_NEED_LENGTH) // add length of length if needed
|
||||
length += psyc_getNumLength(m->value.length) + 1; // SP length
|
||||
|
||||
return length;
|
||||
|
|
|
@ -140,6 +140,7 @@ psycParseRC psyc_parseModifier (psycParseState *state, char *oper,
|
|||
size_t length = 0;
|
||||
value->length = 0;
|
||||
state->valueLength = 0;
|
||||
state->valueLengthFound = 0;
|
||||
state->valueParsed = 0;
|
||||
|
||||
// Parse the value.
|
||||
|
@ -150,6 +151,7 @@ psycParseRC psyc_parseModifier (psycParseState *state, char *oper,
|
|||
|
||||
if (isNumeric(state->buffer.ptr[state->cursor]))
|
||||
{
|
||||
state->valueLengthFound = 1;
|
||||
do
|
||||
{
|
||||
length = 10 * length + state->buffer.ptr[state->cursor] - '0';
|
||||
|
|
7
test/packets/00-length-no-value
Normal file
7
test/packets/00-length-no-value
Normal file
|
@ -0,0 +1,7 @@
|
|||
:_source psyc://foo.example.com/
|
||||
:_target psyc://bar.example.com/
|
||||
|
||||
:_foo 0
|
||||
_message_private
|
||||
OHAI
|
||||
|
|
7
test/packets/00-no-value
Normal file
7
test/packets/00-no-value
Normal file
|
@ -0,0 +1,7 @@
|
|||
:_source psyc://foo.example.com/
|
||||
:_target psyc://bar.example.com/
|
||||
|
||||
:_foo
|
||||
_message_private
|
||||
OHAI
|
||||
|
|
|
@ -234,7 +234,7 @@ int main (int argc, char **argv)
|
|||
if (ret == PSYC_PARSE_ENTITY)
|
||||
{
|
||||
packets[i].entity.lines++;
|
||||
mod->flag = psyc_getParseValueLength(&parsers[i]) ?
|
||||
mod->flag = psyc_isParseValueLengthFound(&parsers[i]) ?
|
||||
PSYC_MODIFIER_NEED_LENGTH : PSYC_MODIFIER_NO_LENGTH;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue