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
187 // much less of a problem, because the host is expected to be present. Yet the host() method must still be187 // much less of a problem, because the host is expected to be present. Yet the host() method must still be
188 // called when handling the None case, to include it in the error. If possible, both methods should be replaced188 // called when handling the None case, to include it in the error. If possible, both methods should be replaced
189 // by methods with a richer return type (a new enum). If not, the ambiguity should be prominently documented.189 // 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()))
191 }192 }
192 193
193 /// Return the password mentioned in the url, if present.194 /// Return the password mentioned in the url, if present.
@@ -211,7 +212,8 @@ impl Url { · 17 unmodified lines
211 ///212 ///
212 /// Use this method if the host is going to be passed to a command-line application.213 /// Use this method if the host is going to be passed to a command-line application.
213 pub fn host_argument_safe(&self) -> Option<&str> {214 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()))
215 }217 }
216 218
217 /// Return the path of this URL *if* it can't be mistaken for a command-line argument.219 /// 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
221 pub fn path_argument_safe(&self) -> Option<&BStr> {223 pub fn path_argument_safe(&self) -> Option<&BStr> {
222 self.path224 self.path
223 .get(1..)225 .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()))
225 }227 }
226 228
227 /// Return true if the path portion of the URL is `/`.229 /// Return true if the path portion of the URL is `/`.
@@ -245,7 +247,7 @@ impl Url { · 17 unmodified lines
245 }247 }
246}248}
247 249
248fn looks_like_argument(b: &[u8]) -> bool {250fn looks_like_command_line_option(b: &[u8]) -> bool {
249 b.first() == Some(&b'-')251 b.first() == Some(&b'-')
250}252}
251 253