You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/02/20 23:19:38 UTC

[GitHub] dubee opened a new pull request #319: Do not fire trigger with invalid JSON

dubee opened a new pull request #319: Do not fire trigger with invalid JSON
URL: https://github.com/apache/incubator-openwhisk-package-kafka/pull/319
 
 
   Due to the default behavior of Python's `json.loads()`, invalid JSON can be passed to the OpenWhisk Controller when firing a trigger. This occurs when constants `NaN`, `Infinity`, `-Infinity` are present in the JSON consumed from Kafka. Such an event results in a `400` HTTP error from the trigger invocation request. When a `400` status code is returned to the Kafka provider, the user's corresponding trigger is automatically disabled.
   
   Showing `json.loads` parsing `NaN` without a failure.
   ```
   json.loads('{"a":[NaN,NaN,123]}')
   {u'a': [nan, nan, 123]}
   ```
   
   Providing a `parse_constant` function allows us to fail when `NaN` is present.
   ```
   json.loads('{"a":[NaN]}', parse_constant=parseJSONConstant)
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 351, in loads
       return cls(encoding=encoding, **kw).decode(s)
     File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
       obj, end = self.raw_decode(s, idx=_w(s, 0).end())
     File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
       obj, end = self.scan_once(s, idx)
     File "<stdin>", line 3, in parseJSONConstant
   ValueError: Invalid JSON detected
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services