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

issue with parsing '-.125' when leading decimal points allowed #777

Merged

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Jun 24, 2022

It's easier to describe the issue with a broken test case. See NonStandardNumberParsingTest and the tests that call _testLeadingDotInDecimalAllowed - I've added an extra scenario for '-.125'.

All of the tests get back 0.125 instead of -0.125.

One issue is that _parseFloatThatStartsWithPeriod has hardcode when calling _parseFloat that says the result is non-negative. I have partially corrected that in this PR but the code still does not work.

@cowtowncoder could you have a look and confirm that this is an issue before I spend more time trying to fix it?

Even after adjusting _parseFloatThatStartsWithPeriod to take a boolean param for the negative flag, the code is running into issues with the TextBuffer and the start pointer that _parseFloat sets on the TextBuffer (that essentially cause the TextBuffer to drop the sign). Messing around with the code for calculating the start pointer has so far caused more problems than it solves.

@@ -115,6 +115,12 @@ private void _testLeadingDotInDecimalAllowed(JsonFactory f, int mode) throws Exc
assertEquals("0.125", p.getDecimalValue().toString());
assertEquals(".125", p.getText());
}
try (JsonParser p = createParser(f, mode, " -.125 ")) {
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(-0.125, p.getValueAsDouble());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is also getDoubleValue(), and variants with Float.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a copy of the previous few lines but testing a different input - the issue is not with me using the wrong method - the jackson code has a bug (in my opinion) that leads to it ignoring the sign on '-.125'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I realized that. What I mean is just that test itself should probably also cover other accessors -- but did not mean to imply that was causing problems or relevant to the actual problem. Methods used are fine, just a subset of all available. So for now we can ignore that.

@cowtowncoder
Copy link
Member

Yes, the issue seems real; let me know if you could use more help with low-level handling. Things do get bit messy with the new options, esp. as much of existing code tries to optimize things to avoid re-constructing textual values etc.

@pjfanning
Copy link
Member Author

Yes, the issue seems real; let me know if you could use more help with low-level handling. Things do get bit messy with the new options, esp. as much of existing code tries to optimize things to avoid re-constructing textual values etc.

So far, I haven't made any progress. Any change I make introduces a different issue.

@cowtowncoder
Copy link
Member

@pjfanning Ok. Maybe we can then start with tests located on a separate individual test class, located under failing and go from there?

@pjfanning
Copy link
Member Author

@pjfanning Ok. Maybe we can then start with tests located on a separate individual test class, located under failing and go from there?

I've moved the failing tests into a new java file. I left the partial refactor of _parseFloatThatStartsWithPeriod because it doesn't make the issue better or worse but knowing whether the number is negative is important information that the full fix will need.

@cowtowncoder
Copy link
Member

Sounds good; I will merge this. Could you also file a separate issue for the problem itself, for tracking purposes? (not 100% sure if it was already failing or not but good to keep track of it).

@cowtowncoder cowtowncoder merged commit 4ca5967 into FasterXML:2.14 Jun 24, 2022
@pjfanning pjfanning deleted the negative-float-without-leading-digit branch June 24, 2022 22:54
pjfanning added a commit to pjfanning/jackson-core that referenced this pull request Jun 24, 2022
@pjfanning
Copy link
Member Author

@cowtowncoder I raised #782

@cowtowncoder
Copy link
Member

Ok. I hope to find time to look into this today; seems like an important thing to fix.

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

Successfully merging this pull request may close these issues.

None yet

2 participants