-
Notifications
You must be signed in to change notification settings - Fork 15
parseAll() hangs if an invalid line is received #18
Comments
@Renegade334 Does this change satisfy your use case? |
Will have a look. As committed, the second group in There are a couple of other ways that the parser could handle such lines: it could strip the invalid characters from the string entirely, or it could reject the entire line but carry on somehow. I am inclined towards stripping as the way to go, as they are invalid whitespace characters that shouldn't be there anyway. The third invalid character is the NUL byte, which should probably be included for completeness. |
Fixed the noted capturing group. The NUL byte is included in alternating groups in the patterns containing |
Sure, but that means that any NUL byte in the input will cause |
Per RFC 2812 Section 2.3.1 Note 2:
Since this doesn't apply to PHP strings, we could allow NUL bytes and optionally strip them out after parsing. Thoughts? |
Well, it's still directly forbidden by the RFC, so I don't think it needs to be optional. Edit: How about ae752e2? |
Stray NUL, CR, and LF bytes will now be stripped from messages prior to them being parsed. This should address the reported issue of such bytes causing the parser to hang. |
If a string containing a non-RFC-compliant line is passed to
parseAll()
, it gets rejected byparse()
and this breaks theparseAll()
loop, on the assumption that the buffer does not yet contain a complete line. This causes the client to hang.For example:
outputs:
Calling
consumeAll()
again would return an empty array, and leave the buffer unchanged; it would never progress beyond the invalid line.Perhaps
parseAll()
should have a way of failing gracefully if an invalid CRLF-terminated line is received.The text was updated successfully, but these errors were encountered: