Skip to content

Commit

Permalink
i18n: Skip and warn about textdomain names with a slash (bug #23839)
Browse files Browse the repository at this point in the history
boost::locale::generator::add_messages_domain() interprets the slash
specially, interpreting everything after it as an encoding name.

It's not clear to me why providing a textdomain with an erroneous name
like this causes Boost.Locale to throw a boost::locale::conv exception
(invalid_charset_error, apparently) when handling t_strings bound to
completely different textdomain, but if we can avoid the issue
altogether then that's good enough.

Made the legacy implementation skip and warn about these names too even
if bindtextdomain(3) says nothing about slashes having a meaning.
  • Loading branch information
irydacea committed Sep 1, 2015
1 parent 1bd91e7 commit 85cf364
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog
Expand Up @@ -21,6 +21,8 @@ Version 1.13.1+dev:
* New generic portraits for the Troll and Troll Whelp
* Language and i18n:
* Updated translations: French, Galician, Japanese, Latvian
* Fixed crashes during start-up on Windows resulting from add-ons containing
erroneous textdomain declarations (bug #23839).
* Lua API:
* Added support for unit.level field (read only)
* Added wesnoth.set_dialog_focus function
Expand Down
2 changes: 2 additions & 0 deletions players_changelog
Expand Up @@ -16,6 +16,8 @@ Version 1.13.1+dev:

* Language and i18n:
* Updated translations: French, Galician, Japanese, Latvian.
* Fixed crashes during start-up on Windows resulting from add-ons containing
erroneous textdomain declarations (bug #23839).

* Music and sound effects:
* New dwarf hit and die sounds.
Expand Down
8 changes: 8 additions & 0 deletions src/gettext.cpp
Expand Up @@ -104,6 +104,14 @@ std::string dsngettext (const char * domainname, const char *singular, const cha

void bind_textdomain(const char* domain, const char* directory, const char* encoding)
{
if(domain != NULL && strchr(domain, '/') != NULL) {
// For compatibility with Boost.Locale implementation, which interprets
// slashes in domain names in a special fashion.
ERR_G << "illegal textdomain name '" << domain
<< "', skipping textdomain\n";
return;
}

if(directory != NULL)
bindtextdomain(domain, directory);
if(encoding != NULL)
Expand Down
12 changes: 12 additions & 0 deletions src/gettext_boost.cpp
Expand Up @@ -96,6 +96,18 @@ namespace
{
return;
}

if(domain.find('/') != std::string::npos)
{
// Forward slash has a specific meaning in Boost.Locale domain
// names, specifying the encoding. We use UTF-8 for everything
// so we can't possibly support that, and odds are it's a user
// mistake (as in bug #23839).
ERR_G << "illegal textdomain name '" << domain
<< "', skipping textdomain\n";
return;
}

generator_.add_messages_domain(domain);
loaded_domains_.insert(domain);
}
Expand Down

0 comments on commit 85cf364

Please sign in to comment.