Changeset 13918 for branches


Ignore:
Timestamp:
Feb 1, 2013, 6:45:23 PM (9 years ago)
Author:
jordan
Message:

(2.7x) #5249 'error parsing json in locales that use , as a decimal separator': backport unit tests and fix from trunk.

Location:
branches/2.7x/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.7x/libtransmission/bencode.c

    r13640 r13918  
    16221622{
    16231623    struct evbuffer * buf = evbuffer_new ();
     1624    char lc_numeric[128];
     1625
     1626    tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
     1627    setlocale (LC_NUMERIC, "C");
    16241628
    16251629    evbuffer_expand (buf, 4096); /* alloc a little memory to start off with */
     
    16441648    }
    16451649
     1650    setlocale (LC_NUMERIC, lc_numeric);
    16461651    return buf;
    16471652}
  • branches/2.7x/libtransmission/json-test.c

    r13625 r13918  
    213213main (void)
    214214{
    215     const testFunc tests[] = { test_elements,
    216                                test_utf8,
    217                                test1,
    218                                test2,
    219                                test3,
    220                                test_unescape };
    221 
    222     return runTests (tests, NUM_TESTS (tests));
    223 }
     215  int i;
     216  int n;
     217  int rv;
     218
     219  const char * comma_locales[] = { "da_DK.UTF-8",
     220                                   "fr_FR.UTF-8",
     221                                   "ru_RU.UTF-8"};
     222
     223  const testFunc tests[] = { test_elements,
     224                             test_utf8,
     225                             test1,
     226                             test2,
     227                             test3,
     228                             test_unescape };
     229
     230  /* run the tests in a locale with a decimal point of '.' */
     231  setlocale (LC_NUMERIC, "C");
     232  if ((rv = runTests (tests, NUM_TESTS (tests))))
     233    return rv;
     234
     235  /* run the tests in a locale with a decimal point of ',' */
     236  n = sizeof(comma_locales) / sizeof(comma_locales[0]);
     237  for (i=0; i<n; ++i)
     238    if (setlocale (LC_NUMERIC, comma_locales[i]) != NULL)
     239      break;
     240  if (i==n)
     241    fprintf (stderr, "WARNING: unable to run locale-specific json tests. add a locale like %s or %s\n",
     242             comma_locales[0],
     243             comma_locales[1]);
     244  else if ((rv = runTests (tests, NUM_TESTS(tests))))
     245    return rv;
     246
     247  /* success */
     248  return 0;
     249}
  • branches/2.7x/libtransmission/json.c

    r13625 r13918  
    280280  jsonsl_t jsn;
    281281  struct json_wrapper_data data;
     282  char lc_numeric[128];
     283
     284  tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
     285  setlocale (LC_NUMERIC, "C");
    282286
    283287  jsn = jsonsl_new (MAX_DEPTH);
     
    310314  tr_ptrArrayDestruct (&data.stack, NULL);
    311315  jsonsl_destroy (jsn);
     316  setlocale (LC_NUMERIC, lc_numeric);
    312317  return error;
    313318}
Note: See TracChangeset for help on using the changeset viewer.