Skip to content

Commit

Permalink
Fix: Disallow revset function names starting with a number.
Browse files Browse the repository at this point in the history
  • Loading branch information
matts1 committed Oct 4, 2024
1 parent 3d26af8 commit 33d6c63
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Breaking changes

* Revset function names can no longer start with a number.

### Deprecations

### New features
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fileset.pest
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ prefix_ops = _{ negate_op }
infix_ops = _{ union_op | intersection_op | difference_op }

function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
function_arguments = {
expression ~ (whitespace* ~ "," ~ whitespace* ~ expression)* ~ (whitespace* ~ ",")?
| ""
Expand Down
8 changes: 8 additions & 0 deletions lib/src/fileset_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ mod tests {
assert_ne!(parse_normalized(r#" foo "#), parse_normalized(r#" "foo" "#));
}

#[test]
fn test_parse_invalid_function_name() {
assert_eq!(
parse_into_kind("5foo(x)"),
Err(FilesetParseErrorKind::SyntaxError)
);
}

#[test]
fn test_parse_whitespace() {
let ascii_whitespaces: String = ('\x00'..='\x7f')
Expand Down
2 changes: 1 addition & 1 deletion lib/src/revset.pest
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ compat_sub_op = { "-" }
infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compat_sub_op }

function = { function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" }
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
keyword_argument = { identifier ~ whitespace* ~ "=" ~ whitespace* ~ expression }
argument = _{ keyword_argument | expression }
function_arguments = {
Expand Down
1 change: 1 addition & 0 deletions lib/src/revset_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ mod tests {
#[test]
fn test_parse_revset_alias_func_decl() {
let mut aliases_map = RevsetAliasesMap::new();
assert!(aliases_map.insert("5func()", r#""is function 0""#).is_err());
aliases_map.insert("func()", r#""is function 0""#).unwrap();
aliases_map
.insert("func(a, b)", r#""is function 2""#)
Expand Down

0 comments on commit 33d6c63

Please sign in to comment.