Issue Details (XML | Word | Printable)

Key: CODEC-73
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Benjamin Bentmann
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Codec

Make string2byte conversions indepedent of platform default encoding

Created: 14/Jul/08 08:52 AM   Updated: 07/Aug/09 08:12 AM
Return to search
Component/s: None
Affects Version/s: 1.3
Fix Version/s: 1.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works CODEC-73.patch 2008-07-14 08:53 AM Benjamin Bentmann 140 kB
Text File Licensed for inclusion in ASF works Hex.patch 2008-07-14 12:08 PM Sebb 5 kB
Environment: any platform whose default encoding is not a superset of ASCII, e.g. UTF-16 or EBCDIC
Issue Links:
Incorporates
 

Resolution Date: 06/Aug/09 06:25 PM


 Description  « Hide
Both the library itself and many of its tests are utterly dependent on the JVM's default charset. For example, DigestUtils calls String.getBytes() to convert an input string to a byte array, happily delivering different digests for the same input string if run on different platforms.

If you want to try out the havor yourself, just run the unit tests in a JVM with UTF-16, e.g. by adding the line

<argLine>-Dfile.encoding=UTF-16</argLine>

to the configuration of the Surefire Plugin in the POM.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Sebb added a comment - 14/Jul/08 11:19 AM
Agreed that the default charset dependency needs to be removed.

However, I have an alternative suggestion:

In the case of the Hex encode() method, one could completely avoid the need to use getBytes() by using a byte[] array for the conversion.

Likewise, I think the Hex decode() could just be performed on bytes rather than converting to char first.

Patch to follow.


Sebb added a comment - 14/Jul/08 12:08 PM
Add byte[] conversion methods (with private toDigit(byte method)

Gary Gregory added a comment - 03/Aug/09 09:51 AM
Fixed DigestUtils and test case.