Skip to content

Commit

Permalink
fix conflict between filesize and hexadecimal numbers (nushell#9309)
Browse files Browse the repository at this point in the history
closes nushell#9278 

# Description

removes ambiguity between the `b` the filesize `bytes` unit and `b` the
hex digit
  • Loading branch information
1Kinoti committed May 28, 2023
1 parent 3005fe1 commit cc04b9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,12 @@ pub fn parse_filesize(working_set: &mut StateWorkingSet, span: Span) -> Expressi

let bytes = working_set.get_span_contents(span);

// the hex digit `b` might be mistaken for the unit `b`, so check that first
if bytes.starts_with(b"0x") {
working_set.error(ParseError::Expected("filesize with valid units", span));
return garbage(span);
}

match parse_unit_value(bytes, span, FILESIZE_UNIT_GROUPS, Type::Filesize, |x| {
x.to_uppercase()
}) {
Expand Down
5 changes: 5 additions & 0 deletions src/tests/test_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,8 @@ fn filesize_with_underscores_2() -> TestResult {
fn filesize_with_underscores_3() -> TestResult {
fail_test("42m_b", "executable was not found")
}

#[test]
fn filesize_is_not_hex() -> TestResult {
run_test("0x42b", "1067")
}

0 comments on commit cc04b9a

Please sign in to comment.