-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve sanitization of expressions received via
--focus-on
- Loading branch information
1 parent
9a0dc9b
commit be07f72
Showing
17 changed files
with
73 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ pub(crate) mod colors; | |
pub(crate) mod graph; | ||
pub(crate) mod item; | ||
pub(crate) mod tree; | ||
pub(crate) mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
use ra_ap_syntax::ast; | ||
|
||
use anyhow::bail; | ||
|
||
pub fn sanitized_use_tree( | ||
focus_on: Option<&str>, | ||
crate_name: &str, | ||
) -> anyhow::Result<ast::UseTree> { | ||
let mut path_expr = focus_on.unwrap_or(crate_name).to_owned(); | ||
|
||
// Trim leading `::` from `use` expression, | ||
// expressions are implied to be absolute: | ||
let double_colon_prefix = "::"; | ||
if path_expr.starts_with(double_colon_prefix) { | ||
let range = 0..(double_colon_prefix.len() - 2); | ||
path_expr.replace_range(range, ""); | ||
} | ||
|
||
let crate_prefix = "crate::"; | ||
if path_expr.starts_with(crate_prefix) { | ||
let range = 0..(crate_prefix.len() - 2); | ||
path_expr.replace_range(range, crate_name); | ||
} | ||
|
||
for keyword in ["super", "self", "$crate"] { | ||
let keyword_prefix = format!("{keyword}::"); | ||
|
||
if path_expr == keyword || path_expr.starts_with(&keyword_prefix) { | ||
bail!("unexpected keyword `{keyword}` in `--focus-on` option"); | ||
} | ||
} | ||
|
||
Ok(crate::analyzer::parse_use_tree(&path_expr)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ expression: output | |
COMMAND: | ||
dependencies | ||
--focus-on | ||
smoke::visibility::* | ||
crate::visibility::* | ||
|
||
STDERR: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters