Repository navigation
Conversation
_parse_timestamp() treated the text after the dot as a fixed-point nanosecond fraction even when the mantissa carried an exponent, so 1.704067200123e9 became 1.7040672 and 1.123456789garbage was silently accepted. Only use the fixed-point branch when the fraction is all digits, and fall through to the float path otherwise. Add sample and exemplar regression tests. Signed-off-by: PerryLink <novelnexusai@outlook.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Parse OpenMetrics timestamps that use exponent notation (
1.704067200123e9) through the float fallback instead of slicing them as fixed-point nanoseconds.Why
_parse_timestamp()first triesint(), then splits on.and keeps the first nine characters of the fractional part as nanoseconds. For a mantissa with an exponent the "fraction" contains the exponent (704067200123e9), so:1.704067200123e9becameTimestamp(1, 704067200)=1.7040672;1.123456789e3became1.123456789;1.123456789garbageparsed as1.123456789.Sample and exemplar timestamps share the helper, and negative exponents were affected too.
Fix
Only take the fixed-point branch when the part after the dot is all digits; otherwise fall through to the existing float path, which produces the expected instant and rejects invalid input. Fixed-point timestamps (up to nanosecond precision) are unchanged.
Reproduction
Tests
test_exponent_timestamps(sample and exemplar timestamps, positive and negative exponents) andtest_invalid_timestamp_after_nanoseconds;python -m pytest tests/openmetrics/test_parser.py -q→ 61 passed;python -m pytest tests/openmetrics tests/test_core.py tests/test_exposition.py -q→ 383 passed, 1 skipped.Fixes #1257