Skip to content

Commit 90eef28

Browse files
authored
CrateScope: Remove crate name normalization (#5575)
As discussed in the team meeting, this should instead be solved by having both variants as dedicated scopes, if necessary.
1 parent a36fc3a commit 90eef28

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/models/token/scopes.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,13 @@ impl CrateScope {
109109
}
110110

111111
pub fn matches(&self, crate_name: &str) -> bool {
112-
let canonicalize = |name: &str| name.replace('-', "_");
113-
114112
if self.pattern == "*" {
115113
return true;
116114
}
117115

118116
return match self.pattern.strip_suffix('*') {
119-
Some(prefix) => {
120-
crate_name.starts_with(prefix)
121-
|| canonicalize(crate_name).starts_with(&canonicalize(prefix))
122-
}
123-
None => {
124-
crate_name == self.pattern
125-
|| canonicalize(crate_name) == canonicalize(&self.pattern)
126-
}
117+
Some(prefix) => crate_name.starts_with(prefix),
118+
None => crate_name == self.pattern,
127119
};
128120
}
129121
}
@@ -174,12 +166,12 @@ mod tests {
174166
assert!(!scope("foo").matches("foo-bar"));
175167
assert!(!scope("foo").matches("foo_bar"));
176168
assert!(scope("foo-bar").matches("foo-bar"));
177-
assert!(scope("foo-bar").matches("foo_bar"));
178-
assert!(scope("foo_bar").matches("foo-bar"));
169+
assert!(!scope("foo-bar").matches("foo_bar"));
170+
assert!(!scope("foo_bar").matches("foo-bar"));
179171
assert!(scope("foo_bar").matches("foo_bar"));
180172
assert!(scope("foo-*").matches("foo-bar"));
181-
assert!(scope("foo-*").matches("foo_bar"));
182-
assert!(scope("foo_*").matches("foo-bar"));
173+
assert!(!scope("foo-*").matches("foo_bar"));
174+
assert!(!scope("foo_*").matches("foo-bar"));
183175
assert!(scope("foo_*").matches("foo_bar"));
184176
}
185177
}

0 commit comments

Comments
 (0)