File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -319,8 +319,7 @@ impl Sequence {
319319 // GNU applies -t before complementing a character class.
320320 // That means we must first truncate the expanded, non-complemented
321321 // source set, then complement the truncated prefix to recover the
322- // final translation domain. Complementing first would incorrectly
323- // shrink the complemented domain to the prefix length.
322+ // final translation domain.
324323 let truncated_set1: Vec < _ > = set1
325324 . iter ( )
326325 . flat_map ( Self :: flatten)
@@ -329,6 +328,11 @@ impl Sequence {
329328 set1_solved = ( 0 ..=u8:: MAX )
330329 . filter ( |x| !truncated_set1. contains ( x) )
331330 . collect ( ) ;
331+ // After expansion the complemented domain may be larger than set2.
332+ // Re-check the complement validity constraint.
333+ if set2_uniques. len ( ) > 1 || set1_solved. len ( ) > set2_solved. len ( ) {
334+ return Err ( BadSequence :: ComplementMoreThanOneUniqueInSet2 ) ;
335+ }
332336 } else {
333337 set1_solved. truncate ( set2_solved. len ( ) ) ;
334338 }
Original file line number Diff line number Diff line change @@ -346,9 +346,10 @@ fn test_truncate_applies_before_complement_with_class() {
346346 new_ucmd ! ( )
347347 . args ( & [ "-ct" , "[:digit:]" , "X" ] )
348348 . pipe_in ( "A" )
349- . succeeds ( )
350- . stdout_is ( "X ") ;
349+ . fails ( )
350+ . stderr_contains ( "when translating with complemented character classes, \n string2 must map all characters in the domain to one ") ;
351351}
352+
352353#[ test]
353354fn missing_args_fails ( ) {
354355 let ( _, mut ucmd) = at_and_ucmd ! ( ) ;
You can’t perform that action at this time.
0 commit comments