diff --git a/changelog/0.5.0.md b/changelog/0.5.0.md index 56fbc71d..84f50a52 100644 --- a/changelog/0.5.0.md +++ b/changelog/0.5.0.md @@ -69,7 +69,6 @@ :barbar: b # was ok :barbarbar: c # was ol ``` -- Fix [#246](https://github.com/biojppm/rapidyaml/issues/246): add missing `#define` for the include guard of the amalgamated header. - Fix [#253](https://github.com/biojppm/rapidyaml/issues/253): double-quoted emitter should encode carriage-return `\r` to preserve roundtrip equivalence: ```yaml Tree tree; @@ -83,6 +82,8 @@ EXPECT_EQ(tree2["s"].val(), tree["s"].val()); ``` - Fix [#297](https://github.com/biojppm/rapidyaml/issues/297) ([PR#298](https://github.com/biojppm/rapidyaml/pull/298)): JSON emitter should escape control characters. +- Fix [#292](https://github.com/biojppm/rapidyaml/issues/292) ([PR#299](https://github.com/biojppm/rapidyaml/pull/299)): JSON emitter should quote version string scalars like `0.1.2`. +- Fix [#291](https://github.com/biojppm/rapidyaml/issues/291) ([PR#299](https://github.com/biojppm/rapidyaml/pull/299)): JSON emitter should quote scalars with leading zero, eg `048`. - Fix [#274](https://github.com/biojppm/rapidyaml/issues/274) ([PR#296](https://github.com/biojppm/rapidyaml/pull/296)): Lists with unindented items and trailing empty values parse incorrectly: ```yaml foo: @@ -106,4 +107,5 @@ =VAL :foo =VAL :bar ``` +- Fix [#246](https://github.com/biojppm/rapidyaml/issues/246): add missing `#define` for the include guard of the amalgamated header. - Fix [cmake#8](https://github.com/biojppm/cmake/issues/8): `SOVERSION` missing from shared libraries. diff --git a/ext/c4core b/ext/c4core index 3729e3fd..cad3d1f1 160000 --- a/ext/c4core +++ b/ext/c4core @@ -1 +1 @@ -Subproject commit 3729e3fdfa5df6072e1b2d0dcea755d7e977ad58 +Subproject commit cad3d1f1b385561b9974d1df0032c97bf880f5a1 diff --git a/samples/quickstart.cpp b/samples/quickstart.cpp index 511f4af7..8b5f1f05 100644 --- a/samples/quickstart.cpp +++ b/samples/quickstart.cpp @@ -1211,23 +1211,35 @@ void sample_substr() CHECK(ryml::csubstr("-1234)asdkjh").first_real_span() == "-1234"); CHECK(ryml::csubstr("-1234gasdkjh").first_real_span() == ""); CHECK(ryml::csubstr("1.234 asdkjh").first_real_span() == "1.234"); - CHECK(ryml::csubstr("1.234e5 asdkjh").first_real_span() == "1.234e5"); CHECK(ryml::csubstr("1.234e+5 asdkjh").first_real_span() == "1.234e+5"); CHECK(ryml::csubstr("1.234e-5 asdkjh").first_real_span() == "1.234e-5"); CHECK(ryml::csubstr("1.234 asdkjh").first_real_span() == "1.234"); - CHECK(ryml::csubstr("1.234e5 asdkjh").first_real_span() == "1.234e5"); CHECK(ryml::csubstr("1.234e+5 asdkjh").first_real_span() == "1.234e+5"); CHECK(ryml::csubstr("1.234e-5 asdkjh").first_real_span() == "1.234e-5"); CHECK(ryml::csubstr("-1.234 asdkjh").first_real_span() == "-1.234"); - CHECK(ryml::csubstr("-1.234e5 asdkjh").first_real_span() == "-1.234e5"); CHECK(ryml::csubstr("-1.234e+5 asdkjh").first_real_span() == "-1.234e+5"); CHECK(ryml::csubstr("-1.234e-5 asdkjh").first_real_span() == "-1.234e-5"); + // hexadecimal real numbers CHECK(ryml::csubstr("0x1.e8480p+19 asdkjh").first_real_span() == "0x1.e8480p+19"); CHECK(ryml::csubstr("0x1.e8480p-19 asdkjh").first_real_span() == "0x1.e8480p-19"); CHECK(ryml::csubstr("-0x1.e8480p+19 asdkjh").first_real_span() == "-0x1.e8480p+19"); CHECK(ryml::csubstr("-0x1.e8480p-19 asdkjh").first_real_span() == "-0x1.e8480p-19"); CHECK(ryml::csubstr("+0x1.e8480p+19 asdkjh").first_real_span() == "+0x1.e8480p+19"); CHECK(ryml::csubstr("+0x1.e8480p-19 asdkjh").first_real_span() == "+0x1.e8480p-19"); + // binary real numbers + CHECK(ryml::csubstr("0b101.011p+19 asdkjh").first_real_span() == "0b101.011p+19"); + CHECK(ryml::csubstr("0b101.011p-19 asdkjh").first_real_span() == "0b101.011p-19"); + CHECK(ryml::csubstr("-0b101.011p+19 asdkjh").first_real_span() == "-0b101.011p+19"); + CHECK(ryml::csubstr("-0b101.011p-19 asdkjh").first_real_span() == "-0b101.011p-19"); + CHECK(ryml::csubstr("+0b101.011p+19 asdkjh").first_real_span() == "+0b101.011p+19"); + CHECK(ryml::csubstr("+0b101.011p-19 asdkjh").first_real_span() == "+0b101.011p-19"); + // octal real numbers + CHECK(ryml::csubstr("0o173.045p+19 asdkjh").first_real_span() == "0o173.045p+19"); + CHECK(ryml::csubstr("0o173.045p-19 asdkjh").first_real_span() == "0o173.045p-19"); + CHECK(ryml::csubstr("-0o173.045p+19 asdkjh").first_real_span() == "-0o173.045p+19"); + CHECK(ryml::csubstr("-0o173.045p-19 asdkjh").first_real_span() == "-0o173.045p-19"); + CHECK(ryml::csubstr("+0o173.045p+19 asdkjh").first_real_span() == "+0o173.045p+19"); + CHECK(ryml::csubstr("+0o173.045p-19 asdkjh").first_real_span() == "+0o173.045p-19"); } // see also is_number() diff --git a/src/c4/yml/emit.def.hpp b/src/c4/yml/emit.def.hpp index 653714e0..4aa03c11 100644 --- a/src/c4/yml/emit.def.hpp +++ b/src/c4/yml/emit.def.hpp @@ -879,7 +879,10 @@ template void Emitter::_write_scalar_json(csubstr s, bool as_key, bool was_quoted) { // json only allows strings as keys - if(!as_key && !was_quoted && (s.is_number() || s == "true" || s == "null" || s == "false")) + if((!as_key) + && (!was_quoted) + && ((s.is_number() && !(s.len > 1 && s.str[0] == '0')) + || s == "true" || s == "null" || s == "false")) { this->Writer::_do_write(s); } diff --git a/test/test_json.cpp b/test/test_json.cpp index fb88f06e..d836e517 100644 --- a/test/test_json.cpp +++ b/test/test_json.cpp @@ -220,6 +220,23 @@ broken_value: '0.30.2' )"); } +TEST(emit_json, issue291) +{ + Tree t = parse_in_arena("{}"); + t["james"] = "045"; + auto s = emitrs_json(t); + EXPECT_EQ(s, "{\"james\": \"045\"}"); +} + +TEST(emit_json, issue292) +{ + EXPECT_FALSE(csubstr("0.1.0").is_number()); + Tree t = parse_in_arena("{}"); + t["james"] = "1.2.3"; + auto s = emitrs_json(t); + EXPECT_EQ(s, "{\"james\": \"1.2.3\"}"); +} + TEST(emit_json, issue297) { char yml_buf[] = R"(