1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #8020 from cakebaker/csplit_fix_issues_with_non_ascii_digits

csplit: fix two issues with non ASCII digits
This commit is contained in:
Sylvestre Ledru 2025-05-28 23:25:18 +02:00 committed by GitHub
commit 0523eab9e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -106,8 +106,8 @@ pub fn get_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> {
fn extract_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> { fn extract_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> {
let mut patterns = Vec::with_capacity(args.len()); let mut patterns = Vec::with_capacity(args.len());
let to_match_reg = let to_match_reg =
Regex::new(r"^(/(?P<UPTO>.+)/|%(?P<SKIPTO>.+)%)(?P<OFFSET>[\+-]?\d+)?$").unwrap(); Regex::new(r"^(/(?P<UPTO>.+)/|%(?P<SKIPTO>.+)%)(?P<OFFSET>[\+-]?[0-9]+)?$").unwrap();
let execute_ntimes_reg = Regex::new(r"^\{(?P<TIMES>\d+)|\*\}$").unwrap(); let execute_ntimes_reg = Regex::new(r"^\{(?P<TIMES>[0-9]+)|\*\}$").unwrap();
let mut iter = args.iter().peekable(); let mut iter = args.iter().peekable();
while let Some(arg) = iter.next() { while let Some(arg) = iter.next() {

View file

@ -83,6 +83,15 @@ fn test_up_to_line_sequence() {
assert_eq!(at.read("xx02"), generate(25, 51)); assert_eq!(at.read("xx02"), generate(25, 51));
} }
#[test]
fn test_up_to_line_with_non_ascii_repeat() {
// we use a different error message than GNU
new_ucmd!()
.args(&["numbers50.txt", "10", "{𝟚}"])
.fails()
.stderr_contains("invalid pattern");
}
#[test] #[test]
fn test_up_to_match() { fn test_up_to_match() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -167,6 +176,15 @@ fn test_up_to_match_offset_repeat_twice() {
assert_eq!(at.read("xx03"), generate(32, 51)); assert_eq!(at.read("xx03"), generate(32, 51));
} }
#[test]
fn test_up_to_match_non_ascii_offset() {
// we use a different error message than GNU
new_ucmd!()
.args(&["numbers50.txt", "/9$/𝟚"])
.fails()
.stderr_contains("invalid pattern");
}
#[test] #[test]
fn test_up_to_match_negative_offset() { fn test_up_to_match_negative_offset() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();