mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Fix parsing requirement where a variable follows an operator without a space (#2273)
Fix parsing `pytest;'4.0'>=python_version`, where previously the operator and the variable were incorrectly tokenized as one invalid operator. Fixes #2247
This commit is contained in:
parent
85042308a1
commit
953a13f12e
2 changed files with 14 additions and 2 deletions
|
@ -1710,4 +1710,10 @@ mod tests {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_space_after_operator() {
|
||||
let requirement = Requirement::from_str("pytest;'4.0'>=python_version").unwrap();
|
||||
assert_eq!(requirement.to_string(), "pytest ; '4.0' >= python_version");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1150,9 +1150,15 @@ impl Display for MarkerTree {
|
|||
/// version_cmp = wsp* <'<=' | '<' | '!=' | '==' | '>=' | '>' | '~=' | '==='>
|
||||
/// marker_op = version_cmp | (wsp* 'in') | (wsp* 'not' wsp+ 'in')
|
||||
/// ```
|
||||
/// The `wsp*` has already been consumed by the caller.
|
||||
fn parse_marker_operator(cursor: &mut Cursor) -> Result<MarkerOperator, Pep508Error> {
|
||||
let (start, len) =
|
||||
cursor.take_while(|char| !char.is_whitespace() && char != '\'' && char != '"');
|
||||
let (start, len) = if cursor.peek_char().is_some_and(|c| c.is_alphabetic()) {
|
||||
// "in" or "not"
|
||||
cursor.take_while(|char| !char.is_whitespace() && char != '\'' && char != '"')
|
||||
} else {
|
||||
// A mathematical operator
|
||||
cursor.take_while(|char| matches!(char, '<' | '=' | '>' | '~' | '!'))
|
||||
};
|
||||
let operator = cursor.slice(start, len);
|
||||
if operator == "not" {
|
||||
// 'not' wsp+ 'in'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue