Skip to content

Commit

Permalink
Fix remaining potentially panicking unwraps (fixes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Jan 25, 2024
1 parent 26e32d0 commit f6a13d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ impl Ord for Component<'_> {
self.precedence.cmp(&other.precedence).then_with(|| {
let self_first_char = self.value.bytes().nth(0);
if self_first_char.is_some_and(|ch| is_alpha(ch)) {
// string comparison: one of args is alphabetic, other is too
// string comparison: if one of args is alphabetic, other is too
// (but be sure not to panic by treating empty string as zero byte)
// compare lowercase (which provides us case insensitivity) of their
// first letters
let other_first_char = other.value.bytes().nth(0).unwrap();
to_lower(self_first_char.unwrap()).cmp(&to_lower(other_first_char))
let other_first_char = other.value.bytes().nth(0).unwrap_or(0);
to_lower(self_first_char.unwrap_or(0)).cmp(&to_lower(other_first_char))
} else {
// numeric comparison: compare lengths, then values, which
// allows numeric comparison of arbitrary long numbers
Expand Down

0 comments on commit f6a13d6

Please sign in to comment.