Skip to content

Commit

Permalink
fix versionsort chunk split on non-ASCII numerics
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicarod7 committed Nov 30, 2024
1 parent 0a32a02 commit 334a917
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a> VersionChunkIter<'a> {
break;
}

if !c.is_numeric() {
if !c.is_ascii_digit() {
continue;
}

Expand Down Expand Up @@ -283,6 +283,10 @@ mod test {
source: "009"
})
);

// '๙' = U+0E59 THAI DIGIT NINE, General Category Nd
let mut iter = VersionChunkIter::new("x๙v");
assert_eq!(iter.next(), Some(VersionChunk::Str("x๙v")));
}

#[test]
Expand All @@ -297,6 +301,11 @@ mod test {
input.sort_by(|a, b| version_sort(a, b));
assert_eq!(input, expected);

let mut input = vec!["x๙x", "xéx", "x0x"];
let expected = vec!["x0x", "xéx", "x๙x"];
input.sort_by(|a, b| version_sort(a, b));
assert_eq!(input, expected);

let mut input = vec!["applesauce", "apple"];
let expected = vec!["apple", "applesauce"];
input.sort_by(|a, b| version_sort(a, b));
Expand Down
33 changes: 33 additions & 0 deletions tests/source/versionsort_non_ascii_numerics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::cmp::Ordering;
use print๙msg::print as first_print;
use print0msg::print as second_print;
use printémsg::print as third_print;

fn main() {
first_print();
second_print();
third_print();

assert_eq!("print๙msg".cmp("printémsg"), Ordering::Greater);
}

/// '๙' = 0E59;THAI DIGIT NINE;Nd;
mod print๙msg {
pub fn print() {
println!("Non-ASCII Decimal_Number")
}
}

/// '0' = 0030;DIGIT ZERO;Nd;
mod print0msg {
pub fn print() {
println!("ASCII Decimal_Number")
}
}

/// 'é' = 00E9;LATIN SMALL LETTER E WITH ACUTE;Ll;
mod printémsg {
pub fn print() {
println!("Lowercase_Letter")
}
}
33 changes: 33 additions & 0 deletions tests/target/versionsort_non_ascii_numerics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use print0msg::print as second_print;
use printémsg::print as third_print;
use print๙msg::print as first_print;
use std::cmp::Ordering;

fn main() {
first_print();
second_print();
third_print();

assert_eq!("print๙msg".cmp("printémsg"), Ordering::Greater);
}

/// '๙' = 0E59;THAI DIGIT NINE;Nd;
mod print๙msg {
pub fn print() {
println!("Non-ASCII Decimal_Number")
}
}

/// '0' = 0030;DIGIT ZERO;Nd;
mod print0msg {
pub fn print() {
println!("ASCII Decimal_Number")
}
}

/// 'é' = 00E9;LATIN SMALL LETTER E WITH ACUTE;Ll;
mod printémsg {
pub fn print() {
println!("Lowercase_Letter")
}
}

0 comments on commit 334a917

Please sign in to comment.