mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
(libT) #5249 'error parsing json in some locales': add unit tests to test for this bug.
This commit is contained in:
parent
1d63fc7d22
commit
887850a636
2 changed files with 34 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include <string.h> /* strlen () */
|
#include <string.h> /* strlen () */
|
||||||
|
|
||||||
|
#include <locale.h> /* setlocale() */
|
||||||
|
|
||||||
#define __LIBTRANSMISSION_VARIANT_MODULE___
|
#define __LIBTRANSMISSION_VARIANT_MODULE___
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "utils.h" /* tr_free */
|
#include "utils.h" /* tr_free */
|
||||||
|
@ -221,6 +223,12 @@ test_unescape (void)
|
||||||
int
|
int
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
int n;
|
||||||
|
int rv;
|
||||||
|
char lc_numeric[128];
|
||||||
|
const char * comma_locales[] = { "da_DK.UTF-8", "fr_FR.UTF-8", "ru_RU.UTF-8"};
|
||||||
|
|
||||||
const testFunc tests[] = { test_elements,
|
const testFunc tests[] = { test_elements,
|
||||||
test_utf8,
|
test_utf8,
|
||||||
test1,
|
test1,
|
||||||
|
@ -228,5 +236,23 @@ main (void)
|
||||||
test3,
|
test3,
|
||||||
test_unescape };
|
test_unescape };
|
||||||
|
|
||||||
return runTests (tests, NUM_TESTS (tests));
|
/* run the tests in a locale with a decimal point of '.' */
|
||||||
|
tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
|
||||||
|
setlocale (LC_NUMERIC, "C");
|
||||||
|
if ((rv = runTests (tests, NUM_TESTS (tests))))
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
/* run the tests in a locale with a decimal point of ',' */
|
||||||
|
n = sizeof(comma_locales) / sizeof(comma_locales[0]);
|
||||||
|
for (i=0; i<n; ++i)
|
||||||
|
if (setlocale (LC_NUMERIC, comma_locales[i]) != NULL)
|
||||||
|
break;
|
||||||
|
if (i==n)
|
||||||
|
fprintf (stderr, "WARNING: unable to run locale-specific json tests.\n");
|
||||||
|
else if ((rv = runTests (tests, NUM_TESTS(tests))))
|
||||||
|
return rv;
|
||||||
|
setlocale (LC_NUMERIC, lc_numeric);
|
||||||
|
|
||||||
|
/* success */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -806,7 +806,7 @@ tr_variantWalk (const tr_variant * v,
|
||||||
|
|
||||||
/* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
|
/* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
|
||||||
tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
|
tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
|
||||||
setlocale (LC_NUMERIC, "POSIX");
|
setlocale (LC_NUMERIC, "C");
|
||||||
|
|
||||||
nodeConstruct (&stack[stackSize++], v, sort_dicts);
|
nodeConstruct (&stack[stackSize++], v, sort_dicts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue