Skip to content

json::from_cbor does not respect allow_exceptions = false when input is string literal #1715

Description

@misos1
  • What is the issue you have?

Function json::from_cbor throws exception even with allow_exceptions = false when input is string literal.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
#include <stdio.h>
#include "json.hpp"

using namespace nlohmann;

int main()
{
	json cbor = json::from_cbor("A", true, false);
	printf("is_discarded: %i\n", cbor.is_discarded());
	return 0;
}

Note json::from_cbor:

    static basic_json from_cbor(detail::input_adapter&& i,
                                const bool strict = true,
                                const bool allow_exceptions = true)
  • What is the expected behavior?

It should print is_discarded: 1.

  • And what is the actual behavior instead?

Throws exception:

terminate called after throwing an instance of 'nlohmann::detail::parse_error'
  what():  [json.exception.parse_error.112] parse error at byte 1: syntax error
while parsing CBOR value: invalid byte: 0x41
exited, aborted

Clang 7.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions