forked from mirrors/jj
Fix: Disallow revset function names starting with a number.
This commit is contained in:
parent
3d26af876f
commit
6878b5047b
5 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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* ~ ",")?
|
||||
| ""
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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""#)
|
||||
|
|
Loading…
Reference in a new issue