Author: carnold Date: Sun Aug 23 23:24:37 2009 New Revision: 807031 URL: http://svn.apache.org/viewvc?rev=807031&view=rev Log: LOGCXX-340: Transcoder::encodeCharsetName bungles encoding
Modified: logging/log4cxx/trunk/src/changes/changes.xml logging/log4cxx/trunk/src/main/cpp/transcoder.cpp logging/log4cxx/trunk/src/test/cpp/helpers/transcodertestcase.cpp Modified: logging/log4cxx/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/changes/changes.xml?rev=807031&r1=807030&r2=807031&view=diff ============================================================================== --- logging/log4cxx/trunk/src/changes/changes.xml (original) +++ logging/log4cxx/trunk/src/changes/changes.xml Sun Aug 23 23:24:37 2009 @@ -22,7 +22,7 @@ <title>Apache log4cxx</title> </properties> <body> -<release version="0.11.0" date="2008-XX-XX" description="Maintenance release"> +<release version="0.11.0" date="2009-XX-XX" description="Maintenance release"> <action issue="LOGCXX-249">Console appender crashes if layout is not set</action> <action issue="LOGCXX-262">socketappendertestcase and xmlsocketappendertestcase not run</action> <action issue="LOGCXX-263">Bad link to log4cxx-dev archive</action> @@ -52,6 +52,7 @@ <action issue="LOGCXX-300">ODBCAppender connection settings broken (or just have changed).</action> <action issue="LOGCXX-303">DOMConfigurator does not set ErrorHandler.</action> <action issue="LOGCXX-304">BasicConfigurator::configure results in writer not set warning.</action> +<action issue="LOGCXX-340">Transcoder::encodeCharsetName bungles encoding</action> </release> <release version="0.10.0" date="2008-04-03" description="First Apache release"> <action issue="LOGCXX-2">logger.h includes config.h</action> Modified: logging/log4cxx/trunk/src/main/cpp/transcoder.cpp URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/transcoder.cpp?rev=807031&r1=807030&r2=807031&view=diff ============================================================================== --- logging/log4cxx/trunk/src/main/cpp/transcoder.cpp (original) +++ logging/log4cxx/trunk/src/main/cpp/transcoder.cpp Sun Aug 23 23:24:37 2009 @@ -523,13 +523,13 @@ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', ' ' }; + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~' }; std::string out; for(LogString::const_iterator iter = val.begin(); iter != val.end(); iter++) { - if (*iter >= 0x30 && *iter < 0x7F) { - out.append(1, asciiTable[*iter - 0x30]); + if (*iter >= 0x20 && *iter < 0x7F) { + out.append(1, asciiTable[*iter - 0x20]); } else { out.append(1, LOSSCHAR); } Modified: logging/log4cxx/trunk/src/test/cpp/helpers/transcodertestcase.cpp URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/helpers/transcodertestcase.cpp?rev=807031&r1=807030&r2=807031&view=diff ============================================================================== --- logging/log4cxx/trunk/src/test/cpp/helpers/transcodertestcase.cpp (original) +++ logging/log4cxx/trunk/src/test/cpp/helpers/transcodertestcase.cpp Sun Aug 23 23:24:37 2009 @@ -60,7 +60,9 @@ LOGUNIT_TEST(uencode3); LOGUNIT_TEST(uencode5); #endif - + LOGUNIT_TEST(encodeCharsetName1); + LOGUNIT_TEST(encodeCharsetName2); + LOGUNIT_TEST(encodeCharsetName3); LOGUNIT_TEST_SUITE_END(); @@ -304,6 +306,34 @@ #endif + void encodeCharsetName1() { + const logchar utf8[] = { 0x75, 0x74, 0x66, 0x2D, 0x38, 0x00 }; + std::string encoded(Transcoder::encodeCharsetName(LogString(utf8))); + LOGUNIT_ASSERT_EQUAL(std::string("utf-8"), encoded); + } + + void encodeCharsetName2() { + logchar lascii[0x60]; + char ascii[0x60]; + for(int i = 0; i < 0x5F; i++) { + lascii[i] = i + 0x20; + ascii[i] = i + 0x20; + } + lascii[0x5F] = 0; + ascii[0x5F] = 0; + std::string encoded(Transcoder::encodeCharsetName(LogString(ascii))); + LOGUNIT_ASSERT_EQUAL(std::string(" !\"#$%&'()*+,-./"), encoded.substr(0, 0x10)); + if (0x40 == 'A') { + LOGUNIT_ASSERT_EQUAL(std::string(ascii), encoded); + } + } + + void encodeCharsetName3() { + logchar unsupported[] = { 0x1F, 0x7F, 0x80, 0x81, 0x00 }; + std::string encoded(Transcoder::encodeCharsetName(LogString(unsupported))); + LOGUNIT_ASSERT_EQUAL(std::string("????"), encoded); + } + }; LOGUNIT_TEST_SUITE_REGISTRATION(TranscoderTestCase);