Skip to content

Commit 350da20

Browse files
committed
"Fix" the Submodule::url_bytes signature
Apparently this can legitimately return a null pointer! We'll actually fix the signature on the next major version bump Closes rust-lang#348
1 parent 27deee9 commit 350da20

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/submodule.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,26 @@ impl<'repo> Submodule<'repo> {
3737

3838
/// Get the submodule's url.
3939
///
40-
/// Returns `None` if the url is not valid utf-8
41-
pub fn url(&self) -> Option<&str> { str::from_utf8(self.url_bytes()).ok() }
40+
/// Returns `None` if the url is not valid utf-8 or if the URL isn't present
41+
pub fn url(&self) -> Option<&str> {
42+
self.opt_url_bytes().and_then(|b| str::from_utf8(b).ok())
43+
}
4244

4345
/// Get the url for the submodule.
46+
#[doc(hidden)]
47+
#[deprecated(note = "renamed to `opt_url_bytes`")]
4448
pub fn url_bytes(&self) -> &[u8] {
49+
self.opt_url_bytes().unwrap()
50+
}
51+
52+
/// Get the url for the submodule.
53+
///
54+
/// Returns `None` if the URL isn't present
55+
// TODO: delete this method and fix the signature of `url_bytes` on next
56+
// major version bump
57+
pub fn opt_url_bytes(&self) -> Option<&[u8]> {
4558
unsafe {
46-
::opt_bytes(self, raw::git_submodule_url(self.raw)).unwrap()
59+
::opt_bytes(self, raw::git_submodule_url(self.raw))
4760
}
4861
}
4962

0 commit comments

Comments
 (0)