History

Give `looks_like_argument` a more accurate name

This renames it to `looks_like_command_line_option`, because both options and non-option arguments are arguments. The condition it checks for is that something looks like an option and therefore should *not* be used as a command-line argument.

Eliah Kagan committed 2 years ago

Commit beef8d21 parent 2e7517e1 file · +6 −4Browse files

Unified · Split

gix-url/src/lib.rs+6−4
@@ -187,7 +187,8 @@ impl Url { · 186 unmodified lines
187187 // much less of a problem, because the host is expected to be present. Yet the host() method must still be
188188 // called when handling the None case, to include it in the error. If possible, both methods should be replaced
189189 // by methods with a richer return type (a new enum). If not, the ambiguity should be prominently documented.
190− self.user().filter(|user| !looks_like_argument(user.as_bytes()))
190+ self.user()
191+ .filter(|user| !looks_like_command_line_option(user.as_bytes()))
191192 }
192193
193194 /// Return the password mentioned in the url, if present.
@@ -211,7 +212,8 @@ impl Url { · 17 unmodified lines
211212 ///
212213 /// Use this method if the host is going to be passed to a command-line application.
213214 pub fn host_argument_safe(&self) -> Option<&str> {
214− self.host().filter(|host| !looks_like_argument(host.as_bytes()))
215+ self.host()
216+ .filter(|host| !looks_like_command_line_option(host.as_bytes()))
215217 }
216218
217219 /// Return the path of this URL *if* it can't be mistaken for a command-line argument.
@@ -221,7 +223,7 @@ impl Url { · 3 unmodified lines
221223 pub fn path_argument_safe(&self) -> Option<&BStr> {
222224 self.path
223225 .get(1..)
224− .and_then(|truncated| (!looks_like_argument(truncated)).then_some(self.path.as_ref()))
226+ .and_then(|truncated| (!looks_like_command_line_option(truncated)).then_some(self.path.as_ref()))
225227 }
226228
227229 /// Return true if the path portion of the URL is `/`.
@@ -245,7 +247,7 @@ impl Url { · 17 unmodified lines
245247 }
246248 }
247249
248−fn looks_like_argument(b: &[u8]) -> bool {
250+fn looks_like_command_line_option(b: &[u8]) -> bool {
249251 b.first() == Some(&b'-')
250252 }
251253