Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsoncons::semantic_tag::uri incorrectly encoded #238

Closed
lrosenthol opened this issue May 13, 2020 · 3 comments
Closed

jsoncons::semantic_tag::uri incorrectly encoded #238

lrosenthol opened this issue May 13, 2020 · 3 comments

Comments

@lrosenthol
Copy link

The following code:

        std::vector<uint8_t> odata;
        jsoncons::ojson oj(jsoncons::json_object_arg);
        oj.insert_or_assign("timestamp", jsoncons::ojson("05-12-2020", jsoncons::semantic_tag::datetime) );
        oj.insert_or_assign("URL", jsoncons::ojson("http://www.domain.com", jsoncons::semantic_tag::uri) );
        jsoncons::cbor::encode_cbor(oj, odata);
        jsoncons::ojson oj2 = jsoncons::cbor::decode_cbor<jsoncons::ojson>(odata);
        std::cout << "(oj)\n" << pretty_print(oj2) << "\n\n";

produces the following (incorrect) output:

(oj)
{
    "timestamp": "05-12-2020", 
    "URL": -1
}

I have also verified that the encoder is the problem by taking the binary output and putting it into (http://cbor.me) and receiving the same -1 result.

danielaparker added a commit that referenced this issue May 14, 2020
danielaparker added a commit that referenced this issue May 14, 2020
@danielaparker
Copy link
Owner

danielaparker commented May 14, 2020

Thanks for reporting. Yes, it's a bug with encoding text strings with semantic tags uri, base64 and base64url into CBOR tags. Fixed on master. Now we have,

std::vector<uint8_t> odata;
jsoncons::ojson oj(jsoncons::json_object_arg);
oj.try_emplace("timestamp", "05-12-2020", jsoncons::semantic_tag::datetime);
oj.try_emplace("URL", "http://www.domain.com", jsoncons::semantic_tag::uri);
jsoncons::cbor::encode_cbor(oj, odata);
jsoncons::ojson oj2 = jsoncons::cbor::decode_cbor<jsoncons::ojson>(odata);
std::cout << "(oj)\n" << pretty_print(oj2) << "\n\n";
std::cout << oj2["timestamp"].as<std::string>() << ", " << oj2["timestamp"].tag() << "\n";
std::cout << oj2["URL"].as<std::string>() << ", " << oj2["URL"].tag() << "\n";

Output:

(oj)
{
    "timestamp": "05-12-2020",
    "URL": "http://www.domain.com"
}

05-12-2020, datetime
http://www.domain.com, uri

@lrosenthol
Copy link
Author

Wonderful - thanks for the fast action. Checking it out now.

and somehow missed try_emplace will "try" to use that more...

@lrosenthol
Copy link
Author

Fix verified - please consider this closed from my perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants