fktn-k / fkYAML

A C++ header-only YAML library
MIT License
67 stars 7 forks source link

parsing yaml file throw exception while decimal number end with dot `.` #380

Closed realysy closed 1 month ago

realysy commented 1 month ago

Description

If a yaml file contains number end with dot ., for example score: 2., fkyaml::node::deserialize() will throw exception:

test: /home/name/fkYAML/include/fkYAML/detail/input/scalar_scanner.hpp:188: static fkyaml::v0_3_10::detail::lexical_token_t fkyaml::v0_3_10::detail::scalar_scanner::scan_after_decimal_point(std::__cxx11::basic_string<char>::const_iterator, std::size_t, bool): Assertion `size > 0' failed.

Reproduction steps

To reproduce, use fkYAML to parse this yaml file:

score: 2.

Also, number in array will cause exception:

data: [1., 2.]

I parse yaml file use the following code:

#include <fstream>
#include "fkYAML/node.hpp"

int main(int argc, char* argv[])
{
    std::ifstream ifs("example.yml");
    fkyaml::node root = fkyaml::node::deserialize(ifs);
    ifs.close();

    return 0;
}

I add fkYAML into my cmake project use add_subdirectory().

Expected vs. actual results

Actual result: parse fail if number end with dot . in yaml file. Expect: parse as float or double number successfully.

Minimal code example

No response

Error messages

No response

Compiler and operating system

ubuntu 20.04, CXX compiler: c++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0

Library version

v0_3_10

Validation

fktn-k commented 1 month ago

@realysy
Thanks for filing the issue.
That must be a bug or the library is missing implementation to process such values.
That should be fixed in a short while in either cases.
In the meantime, could you append 0 to such values.

fktn-k commented 1 month ago

@realysy
While debugging the issue, it's turned out that the library didn't properly handle floating point values which ends with a dot.
So, I've fixed the issue reported above by the PR #382.
Although all the checks during the CI workflows passed successfully, could you confirm if the fix works in your environment too?

realysy commented 1 month ago

@fktn-k Yes, the problem is also fixed in my environment after pulling your fix. Thanks for your fast and effective work!

fktn-k commented 1 month ago

@realysy
Thanks for your confirmation!
I'll close this issue then.
Feel free to reopen it if you notice anything related but still unresolved.