Commit Graph

93 Commits

Author SHA1 Message Date
Petri Lehtinen
e0a7f81b39 Really fix the off-by-one error in json_array_remove()
It didn't affect only the last element but all of them. One item too
much was always moved.
2012-12-04 21:20:59 +02:00
Petri Lehtinen
54d59c743c Fix an off-by-one error in json_array_remove()
Uninitialized memory was read when the last item of a "full" array was
removed.
2012-12-04 09:32:45 +02:00
Bert Wesarg
4853a3454c Support building and testing with VPATH. 2012-10-26 14:43:46 +02:00
Petri Lehtinen
4118315afa Disallow NaN or Inf real values 2012-09-13 21:30:19 +03:00
Petri Lehtinen
0b871a113c Merge branch '2.3' 2012-08-11 20:45:15 +03:00
Alessandro Ghedini
8176527f56 fix check-exports test on ppc64 2012-08-11 20:42:21 +03:00
Petri Lehtinen
b6a1d8cfd4 Add json_boolean() macro
Mostly for symmetry reasons. Makes it easier e.g. to:

  int ok = 0;
  if(something)
      ok = 1;

  json_object_set_new(obj, "ok", json_boolean(ok));

Fixes #86.
2012-07-30 07:20:37 +03:00
Petri Lehtinen
2d46ea069b Merge branch 'fix-slash' of git://github.com/jrbasso/jansson
Fixes #81.
2012-06-29 13:24:55 +03:00
Juan Basso
b217cd6689 Created flag to dump escaping slash 2012-06-28 22:04:36 -04:00
Juan Basso
a0c262d08b Escaping the slash when dump 2012-06-27 23:54:08 -04:00
Petri Lehtinen
6ce273e2e6 Merge branch '2.3' 2012-06-06 21:10:28 +03:00
Paul Harris
f62b1f5d69 Bugfix: must cast void* to do pointer math
Fixes #78.
2012-06-06 21:09:47 +03:00
Paul Harris
2b87fdcb43 Bugfix: Changed all use of ssize_t to size_t.
ssize_t is only used in a test, and its comparing to a size_t variable.

Fixes #77.
2012-06-06 08:47:17 +03:00
Petri Lehtinen
ff0c05b8f1 Support building on Windows
Jansson now builds correctly with Visual C++ Express 2010.
2012-04-29 22:09:29 +03:00
Petri Lehtinen
e8fd3e3085 Document and tweak json_load_callback()
Change the return value of json_load_callback_t to size_t, as it's
feels more correct. The callback should return (size_t)-1 on failure.

Issue #57.
2012-03-26 21:53:21 +03:00
Petri Lehtinen
09c39adc55 Add json_load_callback to the list of exported symbols 2012-03-22 09:02:49 +02:00
Rogerz Zhang
040bd7b0fa Add json_load_callback() 2012-03-22 14:52:57 +08:00
Petri Lehtinen
3c6e36ba2d Update copyright notices for 2012 2012-03-20 20:55:55 +02:00
Petri Lehtinen
6ac6f311b5 Fix tests on shells that don't support the export FOO=bar syntax 2012-03-08 15:01:52 +02:00
Petri Lehtinen
54d88753a6 Disribute the check-exports tests 2012-02-12 16:05:27 +02:00
Petri Lehtinen
0d64e8ef89 Make test_load.c not depend on the C locale
Fixes #51.
2012-01-30 21:23:18 +02:00
Petri Lehtinen
6cb14dd337 Add support for optional object keys for json_unpack() and friends
Initial patch by Andrew Thompson.
2012-01-26 21:16:36 +02:00
Petri Lehtinen
fa268b5017 Add json_object_update_{existing,missing}
Closes #37.
2012-01-24 21:03:36 +02:00
Petri Lehtinen
a307974731 Implement json_object_foreach()
Also change many places to use it internally to replace hand-crafted
iteration.

Closes #45, #46.
2012-01-24 21:01:24 +02:00
Petri Lehtinen
a2381948bb Make hashtable less generic
This will make it possible to implement json_object_foreach(). It
should also have some (positive) effect on speed.
2012-01-24 21:01:23 +02:00
Petri Lehtinen
f471e63bb3 Write number of bytes read to error position on successful decode
Closes #49.
2012-01-23 21:18:04 +02:00
Petri Lehtinen
bef87fc258 Merge branch '2.2'
Closes GH-43.
2011-11-14 21:11:18 +02:00
Andrea Marchesini
1e36667193 JSON_DECODE_ANY
Closes GH-4.
2011-11-14 21:10:09 +02:00
Andrea Marchesini
5ec101ec21 json_load* return NULL if the first argument is NULL 2011-11-14 20:57:41 +02:00
Petri Lehtinen
8484ea3fb2 Remove '+' and leading zeros from exponents in the encoder
Fixes GH-39.
2011-11-01 20:50:16 +02:00
Petri Lehtinen
d7ddbf3661 Make real number encoding and decoding work under all locales
The decimal point '.' is changed to locale's decimal point
before/after JSON conversion to make C standard library's
locale-specific string conversion functions work correctly.

All the tests now call setlocale(LC_ALL, "") on startup to use the
locale set in the environment.

Fixes GH-32.
2011-10-02 21:31:17 +03:00
JKL
54f38d250c test file for new json_dump_callback function 2011-06-30 21:47:12 +03:00
Petri Lehtinen
a76ba52f34 Add JSON_DISABLE_EOF_CHECK decoding flag
With this flag enabled, the decoder stops after a valid JSON input and
thus allows extra data after it.

Fixes GH-25.
2011-05-29 21:27:15 +03:00
Petri Lehtinen
49fc708d4c Add JSON_REJECT_DUPLICATES decoding flag
With this flag, a decoding error is issued if any JSON object in the
input contains duplicate keys.

Fixes GH-3.
2011-05-15 13:57:49 +03:00
Petri Lehtinen
636d5f60f9 Add JSON_ENCODE_ANY flag to allow encoding any JSON value
Closes GH-19.
2011-05-14 12:57:12 +03:00
Petri Lehtinen
b44e2be032 Add json_loadb() for decoding possibly non null-terminated strings
Thanks to Jonathan Landis for the initial patch.
2011-04-10 21:01:50 +03:00
Jim Meyering
c96763215d Avoid set-but-not-used warning/error in a test
Closes GH-20.
2011-04-05 15:36:13 +03:00
Petri Lehtinen
0944ac8d91 Fix invalid object key hashing in json_unpack() strict checking mode
The keys which are stored temporarily to a hashtable to make sure that
all object keys are unpacked, were hashed with the object key hashing
function. It is meant to compute hashes for object_key_t values, and
it works incorrectly for plain strings.

Fixed by introducing suitable functions for hashing and comparing
strings for string-keyed hashtables.
2011-03-30 12:57:48 +03:00
Petri Lehtinen
38e35e0973 Test framework enhancements, fix the check_exports test
* Use "printf" instead of "echo -n" as it's more portable
* Treat a test as skipped if it exits with exit status of 77
* Skip the check_exports test if "nm -D" doesn't work
2011-03-27 13:34:43 +03:00
Petri Lehtinen
42b651ef56 Fix packing of invalid UTF-8 strings 2011-02-27 21:34:12 +02:00
Petri Lehtinen
cd854b5bc2 tests: Add missing json_decref() calls to suites/api/test_unpack.c 2011-02-25 22:24:12 +02:00
Petri Lehtinen
dd9b4e530c Remove invalid subdirs from test/suites/Makefile.am 2011-02-25 21:09:04 +02:00
Petri Lehtinen
58f9d65535 Add lots of tests for pack/unpack code, fix bugs found
Closes GH-12.
2011-02-22 19:08:51 +02:00
Petri Lehtinen
5df7b79397 Refactor decoder input stream
- Add a new field position to the json_error_t structure. This is the
  position in bytes from the beginning of the input.

- Keep track of line, column and input position in the stream level.
  Previously, only line was tracked, and it was in the lexer level, so
  this info was not available for UTF-8 decoding errors.

- While at it, refactor tests so that no separate "stripped" tests are
  required. json_process is now able to strip whitespace from its
  input, and the "valid" and "invalid" test suites now use this to
  test both non-stripped and stripped input.

Closes GH-9.
2011-02-22 12:07:37 +02:00
Petri Lehtinen
4be9e9e7fe Add custom memory allocation
Thanks to Basile Starynkevitch for the suggestion and initial patch.
Thanks to Jonathan Landis and Deron Meranda for showing how this can
be utilized for implementing secure memory operations.
2011-02-17 10:10:53 +02:00
Petri Lehtinen
579c291882 Expand the pack/unpack API, implement unpack flags
Expand the pack/unpack API: json_(un)pack is the simple version with
no error output, json_(un)pack_ex has error output and flags,
json_v(un)pack_ex is a va_list version of json_(un)pack_ex.

Implement unpacking flags:

- JSON_UNPACK_ONLY turns off extra validation, i.e. array and object
  unpacking doesn't check that all items are unpacked. This is really
  just convenience for not adding '*' after each object and array.

- JSON_VALIDATE_ONLY turns off unpacking, i.e. no varargs are expected
  and nothing is unpacked.
2011-01-25 10:02:27 +02:00
Petri Lehtinen
7f3018a4fb Refactor json_pack()
* Implement a "scanner" that reads the format string, maintaining state

* Split json_vnpack() to three separate functions for packing objects,
  arrays and simple values. This makes it more clear what is being
  packed, and the object and array structures become more evident.

* Make the skipping of ignored character simpler, i.e. skip ':' and
  ',' independent of their context

This patch shaves around 80 lines of code from the original
implementation.
2011-01-24 21:26:23 +02:00
Petri Lehtinen
53383860e8 Unify style 2011-01-24 21:14:55 +02:00
Petri Lehtinen
fa7c2ea070 Update copyright notices for 2011 2011-01-22 13:43:14 +02:00
Graeme Smecher
3a7512d2b0 Make json_pack/json_unpack() recursive
Note that we pass va_list pointers around instead of just va_lists, which
would seem more intuitive. This is necessary since the behaviour of va_lists
passed as function parameters is finicky. Quoth stdarg(3):

	If ap is passed to a function that uses va_arg(ap,type) then the value
	of ap is undefined after the return of that function.

The pointer-passing strategy is used by Python's Py_BuildValue() for the same
purpose.
2011-01-14 21:43:48 +02:00