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

Poco::NumberParser::tryParseHex raise Poco::SyntaxException exception. #4859

Closed
uzanka opened this issue Jan 31, 2025 · 4 comments · Fixed by #4860
Closed

Poco::NumberParser::tryParseHex raise Poco::SyntaxException exception. #4859

uzanka opened this issue Jan 31, 2025 · 4 comments · Fixed by #4860
Assignees
Labels

Comments

@uzanka
Copy link

uzanka commented Jan 31, 2025

Describe the bug
The following functions raise Poco::SyntaxException exceptions:
Poco::NumberParser::tryParseHex, ... (all tryParse* ?)

Expected behavior
tryParse* functions does not raise any exceptions.

Logs
NumericString.h : strToInt

		if (*pStr == thSep)
		{
			if (base == 10) continue;
			throw Poco::SyntaxException("strToInt: thousand separators only allowed for base 10");
		}

Please add relevant environment information:

  • OS: Windows11
  • POCO Version: 1.12, or later
    (The problem does not occur in version 1.9.)
@uzanka uzanka added the bug label Jan 31, 2025
@matejk
Copy link
Contributor

matejk commented Jan 31, 2025

@uzanka , does the problem occur with the latest version also (1.14.0)?

@uzanka
Copy link
Author

uzanka commented Feb 1, 2025

The problem also occurs in 1.14.1

Sample code and results.

#include <iostream>
#include "Poco/NumberParser.h"
#include "Poco/Exception.h"

int main() {
    try {
      unsigned int value = 0;
      bool result = Poco::NumberParser::tryParseHex("0,2", value);
      std::cout << result << std::endl;
      std::cout << value << std::endl;
      return 0;
    } catch (Poco::Exception& exc) {
      std::cout << exc.displayText() << std::endl;
      return 1;
    }
}
D:\test\ConsoleApplication2\x64\Debug>ConsoleApplication2.exe
Syntax error: strToInt: thousand separators only allowed for base 10

D:\test\ConsoleApplication2\x64\Debug>echo %ERRORLEVEL%
1

@matejk matejk added this to the Release 1.14.1 milestone Feb 2, 2025
@matejk matejk added this to 1.14 Feb 2, 2025
@ssooffiiaannee
Copy link

Why "Expected behavior tryParse* functions does not raise any exceptions" ? isn't this an expected behavior ? hex shall not expect commas

@uzanka
Copy link
Author

uzanka commented Feb 3, 2025

Why do you think the string you give us is just a valid hexadecimal number?

Why do you think there are two types of parse and tryParse?

If tryParse raises an exception, then parse is enough. No need for tryParse.

@matejk matejk self-assigned this Feb 3, 2025
@matejk matejk moved this to In Progress in 1.14 Feb 3, 2025
@matejk matejk moved this from In Progress to Done in 1.14 Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants