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

Bug/581 read any signs #587

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions nemo-physical/src/datavalues/any_datavalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ impl AnyDataValue {
let mut sign_plus = true;
let mut is_zero = true;
let mut has_nonzero_fraction = false;

let mut saw_digit = false;

for char in lexical_value.bytes() {
match char {
b'-' => {
Expand All @@ -370,6 +373,7 @@ impl AnyDataValue {
}
}
b'1'..=b'9' => {
saw_digit = true;
trimmed_value.push(char::from(char));
in_leading_zeros = false;
is_zero = false;
Expand All @@ -379,6 +383,7 @@ impl AnyDataValue {
}
}
b'0' => {
saw_digit = true;
before_sign = false;
if !in_leading_zeros {
trimmed_value.push('0');
Expand All @@ -401,6 +406,12 @@ impl AnyDataValue {
}
}
}

// If we didn't see any digits then this is not a decimal
if !saw_digit {
return Self::decimal_parse_error(lexical_value, decimal_type);
}

// finally remove trailing zeros, and possibly also "."
if in_fraction {
trimmed_value.truncate(len_at_trailing_zeros);
Expand Down
6 changes: 6 additions & 0 deletions resources/testcases/regression/load/sign/run.rls
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%! This test case is based on https://github.com/knowsys/nemo/issues/581.
%! A crash was caused by code responsible for parsing csv-values into any
%! when parsing values like "+" or "-".

@import sign :- csv { resource="../sources/sign.csv", format=(any,)} .
@export sign :- csv {}.
4 changes: 4 additions & 0 deletions resources/testcases/regression/load/sign/run/sign.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
+
-
+.
-.
4 changes: 4 additions & 0 deletions resources/testcases/regression/load/sources/sign.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
+
-
+.
-.
Loading