tr: fix various issues with case conversion
authorPádraig Brady <P@draigBrady.com>
Mon, 27 Sep 2010 06:16:44 +0000 (07:16 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 29 Sep 2010 10:05:12 +0000 (11:05 +0100)
commit3f48829c2939e53c7e961a42d0749765dc076279
tree094154a9b97b0ee973440a915f9fc67474b3c796
parent704eedab034e24814067c535d3577f165c9a8b68
tr: fix various issues with case conversion

This valid translation spec aborted:
  LC_ALL=en_US.iso-8859-1 tr '[:upper:]- ' '[:lower:]_'
This invalid translation spec aborted:
  LC_ALL=en_US.iso-8859-1 tr '[:upper:] '  '[:lower:]'
This was caused by commit 6efd1046, 05-01-2008,
"Avoid tr case-conversion failure in some locales"

This misaligned conversion spec was allowed:
  LC_ALL=C tr 'A-Y[:lower:]' 'a-z[:upper:]'
This was caused by commit af5d0c36, 21-10-2007,
"tr: do not reject an unmatched [:lower:] or [:upper:] in SET1"

This misaligned spec was allowed by extending the class:
  LC_ALL=C tr '[:upper:] ' '[:lower:]'

* src/tr.c (validate_case_classes): A new function to check
alignment of case conversion classes.  Also it adjusts the
length of the sets so that locales with different numbers of
upper and lower case characters, don't cause issues.
(string2_extend): Disallow extending the case conversion
class as in the above example.  That is locale dependent
and most likely not what the user wants.
(validate): Do the simple test for "restricted" char classes
earlier, so we don't redundantly do more expensive validation.
(main): Remove the case class validation, and simplify.
* tests/misc/tr-case-class: A new test to test the various
alignment and locale issues, associated with case conversion.
* tests/misc/tr: Move case conversion tests to new tr-case-class.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the fixes.
NEWS
src/tr.c
tests/Makefile.am
tests/misc/tr
tests/misc/tr-case-class [new file with mode: 0755]