From: Abby K. <Abb...@xc...> - 2012-03-14 16:48:00
|
I am using dnsjava-2.1.3. When converting a record to a String, the Record.byteArrayToString method escapes some characters ('\' and '"') with a '\'. Unfortunately, this means that the resulting string doesn't accurately represent the contents of the message and can cause incorrect results when the string is used as is in other processing. For example, suppose I am handling NAPTR records. NAPTRRecord naptrRecord = ... ; String regExp = naptrRecord.getRegexp(); Suppose the NAPTR record has a regular expression of "!^(.+)$!0\1!". This quite standard regular expression means that the replacement part (between the second two '!') is to be applied to the string matched by the first part (between the first two '!'). In this simple example, we expect the string captured by the first part of the expression, ^(.+)$ - which, in our case, captures the entire string - to be prefixed with the digit 0. However, the NAPTR getRegexp() method calls the byteArrayToString method, thereby escaping the '\', giving the String "!^(.+)$!0\\1!". If used in regular expression processing the additional \ will cause the result to be "0\1", which is incorrect. I could manually replace the escaped characters myself, but since the toString method of the dnsjava classes uses the byteArrayToString method, I wouldn't be able to do this in all uses of the byteArrayToString method. Additionally, there would be some inconsistency in what is displayed in a log file, for example, and what is actually in the wire format of the object. One was of solving this is by providing a byteArray method, which simply returns the wire format of a field. The String(byte []) constructor can be used to convert this to a String. Another option is to simply use the String(byte[]) constructor in the byteArrayToString method. Obviously, this would might problems in displaying unprintable characters, but at theast the String would be an accurate representation of what's in the message. Any assistance would be appreciated. Thanks, Abby. |