diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-17 09:46:50 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-08-10 11:08:27 (GMT) |
| commit | 8ec22a9c5591584fd1725ed028d714c51b7509d3 (patch) | |
| tree | 3687e7023696c9e790a24fd54b7d04f14ac58ab2 /Swiften/IDN/LibIDNConverter.cpp | |
| parent | 5e9e715e49a5ddb6ce9c76ec61e7ecfd6eacdb58 (diff) | |
| download | swift-contrib-8ec22a9c5591584fd1725ed028d714c51b7509d3.zip swift-contrib-8ec22a9c5591584fd1725ed028d714c51b7509d3.tar.bz2 | |
Fix invalid characters being allowed in JID domains
Test-Information:
Prepare valid and invalid JIDs and make sure that isValid() is reported correctly. Added unit tests.
Change-Id: Ic4d86f8b6ea9defc517ada2f8e3cc54979237cf4
Diffstat (limited to 'Swiften/IDN/LibIDNConverter.cpp')
| -rw-r--r-- | Swiften/IDN/LibIDNConverter.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Swiften/IDN/LibIDNConverter.cpp b/Swiften/IDN/LibIDNConverter.cpp index c4a1c18..45b1d14 100644 --- a/Swiften/IDN/LibIDNConverter.cpp +++ b/Swiften/IDN/LibIDNConverter.cpp @@ -33,48 +33,48 @@ namespace { assert(false); return 0; } template<typename StringType, typename ContainerType> ContainerType getStringPreparedInternal(const StringType& s, IDNConverter::StringPrepProfile profile) { ContainerType input(s.begin(), s.end()); input.resize(MAX_STRINGPREP_SIZE); if (stringprep(&input[0], MAX_STRINGPREP_SIZE, static_cast<Stringprep_profile_flags>(0), getLibIDNProfile(profile)) == 0) { return input; } else { return ContainerType(); } } } namespace Swift { std::string LibIDNConverter::getStringPrepared(const std::string& s, StringPrepProfile profile) { std::vector<char> preparedData = getStringPreparedInternal< std::string, std::vector<char> >(s, profile); if (preparedData.empty()) { throw std::exception(); } return std::string(vecptr(preparedData)); } SafeByteArray LibIDNConverter::getStringPrepared(const SafeByteArray& s, StringPrepProfile profile) { std::vector<char, SafeAllocator<char> > preparedData = getStringPreparedInternal<SafeByteArray, std::vector<char, SafeAllocator<char> > >(s, profile); if (preparedData.empty()) { throw std::exception(); } return createSafeByteArray(reinterpret_cast<const char*>(vecptr(preparedData))); } -std::string LibIDNConverter::getIDNAEncoded(const std::string& domain) { +boost::optional<std::string> LibIDNConverter::getIDNAEncoded(const std::string& domain) { char* output; - if (idna_to_ascii_8z(domain.c_str(), &output, 0) == IDNA_SUCCESS) { + if (idna_to_ascii_8z(domain.c_str(), &output, IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS) { std::string result(output); free(output); return result; } else { - return domain; + return boost::optional<std::string>(); } } } |
Swift