Author: mlandres Date: Thu Dec 11 21:44:47 2008 New Revision: 11927 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11927&view=rev Log: - Add str::hexencode and str::hexdecode to encode special characters in a string as %XX. - Hexdecode modalias strings in rpm dependencies because rpm does not allow comma, blank and other special chars. (bnc #456695) Modified: trunk/libzypp/VERSION.cmake trunk/libzypp/package/libzypp.changes trunk/libzypp/tests/zypp/base/String_test.cc trunk/libzypp/zypp/base/String.cc trunk/libzypp/zypp/base/String.h trunk/libzypp/zypp/sat/detail/PoolImpl.cc Modified: trunk/libzypp/VERSION.cmake URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/VERSION.cmake?rev=11927&r1=11926&r2=11927&view=diff ============================================================================== --- trunk/libzypp/VERSION.cmake (original) +++ trunk/libzypp/VERSION.cmake Thu Dec 11 21:44:47 2008 @@ -60,8 +60,8 @@ # SET(LIBZYPP_MAJOR "5") SET(LIBZYPP_COMPATMINOR "23") -SET(LIBZYPP_MINOR "24") -SET(LIBZYPP_PATCH "8") +SET(LIBZYPP_MINOR "25") +SET(LIBZYPP_PATCH "0") # # LAST RELEASED: 5.24.7 (23) # (The number in parenthesis is LIBZYPP_COMPATMINOR) Modified: trunk/libzypp/package/libzypp.changes URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/package/libzypp.changes?rev=11927&r1=11926&r2=11927&view=diff ============================================================================== --- trunk/libzypp/package/libzypp.changes (original) +++ trunk/libzypp/package/libzypp.changes Thu Dec 11 21:44:47 2008 @@ -1,4 +1,13 @@ ------------------------------------------------------------------- +Thu Dec 11 21:39:50 CET 2008 - ma@suse.de + +- Add str::hexencode and str::hexdecode to encode special characters + in a string as %XX. +- Hexdecode modalias strings in rpm dependencies because rpm does not + allow comma, blank and other special chars. (bnc #456695) +- revision 11927 + +------------------------------------------------------------------- Thu Dec 11 17:13:06 CET 2008 - ma@suse.de - Catch and report media errors when proving packages. (bnc #457652) Modified: trunk/libzypp/tests/zypp/base/String_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/base/String_test.cc?rev=11927&r1=11926&r2=11927&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/base/String_test.cc (original) +++ trunk/libzypp/tests/zypp/base/String_test.cc Thu Dec 11 21:44:47 2008 @@ -225,3 +225,28 @@ BOOST_CHECK( ! str::contains("abcXabcYabc", "xabcy") ); BOOST_CHECK( str::containsCI("abcXabcYabc", "xabcy") ); } + +BOOST_AUTO_TEST_CASE(hexencode_hexdecode) +{ + std::string o; + o.reserve( 256 ); + for ( unsigned i = 1; i < 256; ++i ) + o += i; + + std::string e( str::hexencode( o ) ); + // encoded contains nothing but [%a-zA-Z0-9] + for ( unsigned i = 0; i < 255; ++i ) + { + char ch = e[i]; + BOOST_CHECK( ch == '%' + || ( 'a' <= ch && ch <= 'z' ) + || ( 'A' <= ch && ch <= 'Z' ) + || ( '0' <= ch && ch <= '9' ) ); + } + + std::string d( str::hexdecode( e ) ); + BOOST_CHECK( o == d ); +// for ( unsigned i = 0; i < 255; ++i ) +// if ( o[i] != d[i] ) +// WAR << i << " " << unsigned(o[i]) << " != " << unsigned(d[i]) << endl; +} Modified: trunk/libzypp/zypp/base/String.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.cc?rev=11927&r1=11926&r2=11927&view=diff ============================================================================== --- trunk/libzypp/zypp/base/String.cc (original) +++ trunk/libzypp/zypp/base/String.cc Thu Dec 11 21:44:47 2008 @@ -83,6 +83,78 @@ ); } + /////////////////////////////////////////////////////////////////// + // Hexencode + /////////////////////////////////////////////////////////////////// + namespace { + /** What's not decoded. */ + inline bool heIsAlNum( char ch ) + { + return ( ( 'a' <= ch && ch <= 'z' ) + ||( 'A' <= ch && ch <= 'Z' ) + ||( '0' <= ch && ch <= '9' ) ); + } + /** Hex-digit to number or -1. */ + inline int heDecodeCh( char ch ) + { + if ( '0' <= ch && ch <= '9' ) + return( ch - '0' ); + if ( 'A' <= ch && ch <= 'Z' ) + return( ch - 'A' + 10 ); + if ( 'a' <= ch && ch <= 'z' ) + return( ch - 'A' + 10 ); + return -1; + } + } + + std::string hexencode( const C_Str & str_r ) + { + static const char *const hdig = "0123456789ABCDEF"; + std::string res; + res.reserve( str_r.size() ); + for ( const char * it = str_r.c_str(); *it; ++it ) + { + if ( heIsAlNum( *it ) ) + { + res += *it; + } + else + { + res += '%'; + res += hdig[(unsigned char)(*it)/16]; + res += hdig[(unsigned char)(*it)%16]; + } + } + return res; + } + + std::string hexdecode( const C_Str & str_r ) + { + std::string res; + res.reserve( str_r.size() ); + for_( it, str_r.c_str(), str_r.c_str()+str_r.size() ) + { + if ( *it == '%' ) + { + int d1 = heDecodeCh( *(it+1) ); + if ( d1 != -1 ) + { + int d2 = heDecodeCh( *(it+2) ); + if ( d2 != -1 ) + { + res += (d1<<4)|d2; + it += 2; + continue; + } + } + } + // verbatim if no %XX: + res += *it; + } + return res; + } + /////////////////////////////////////////////////////////////////// + /****************************************************************** ** ** FUNCTION NAME : toLower @@ -285,6 +357,7 @@ } + /****************************************************************** ** ** Modified: trunk/libzypp/zypp/base/String.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.h?rev=11927&r1=11926&r2=11927&view=diff ============================================================================== --- trunk/libzypp/zypp/base/String.h (original) +++ trunk/libzypp/zypp/base/String.h Thu Dec 11 21:44:47 2008 @@ -584,6 +584,11 @@ * * For use when printing \a c separated values, and where * \ref joinEscaped() is too heavy. + * + * \todo use C_Str instead of std::string to prevent unnecessary + * promotion to string if used with "string". + * + * \todo shoud not be documented in doxy-group 'Join' */ std::string escape(const std::string & str_r, const char c = ' ' ); @@ -591,6 +596,20 @@ //@} /////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + /** \name Hexencode. + * Encode all characters other than [a-zA-Z0-9] as %XX. + * This includes the % character itself, which becomes %25. + */ + //@{ + /** Encode all characters other than [a-zA-Z0-9] as %XX. + * This includes the % character itself, which becomes %25. + */ + std::string hexencode( const C_Str & str_r ); + /** Decode hexencoded %XX sequences. */ + std::string hexdecode( const C_Str & str_r ); + //@} + /////////////////////////////////////////////////////////////////// /** \name Case conversion. */ //@{ Modified: trunk/libzypp/zypp/sat/detail/PoolImpl.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/detail/PoolImpl.cc?rev=11927&r1=11926&r2=11927&view=diff ============================================================================== --- trunk/libzypp/zypp/sat/detail/PoolImpl.cc (original) +++ trunk/libzypp/zypp/sat/detail/PoolImpl.cc Thu Dec 11 21:44:47 2008 @@ -107,7 +107,11 @@ case NAMESPACE_MODALIAS: { - return target::Modalias::instance().query( IdString(rhs) ) ? RET_systemProperty : RET_unsupported; + // modalias strings in capability may be hexencoded because rpm does not allow + // ',', ' ' or other special chars. + return target::Modalias::instance().query( str::hexdecode( IdString(rhs).c_str() ) ) + ? RET_systemProperty + : RET_unsupported; } break; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org