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 @@ -386,9 +386,10 @@ fn test_truncate_applies_before_complement_with_class() {
386386 new_ucmd ! ( )
387387 . args ( & [ "-ct" , "[:digit:]" , "X" ] )
388388 . pipe_in ( "A" )
389- . succeeds ( )
390- . stdout_is ( "X ") ;
389+ . fails ( )
390+ . stderr_contains ( "when translating with complemented character classes, \n string2 must map all characters in the domain to one ") ;
391391}
392+
392393#[ test]
393394fn missing_args_fails ( ) {
394395 let ( _, mut ucmd) = at_and_ucmd ! ( ) ;
You can’t perform that action at this time.
0 commit comments