Merge branch '1.1'
authorPetri Lehtinen <petri@digip.org>
Wed, 4 Nov 2009 20:10:46 +0000 (22:10 +0200)
committerPetri Lehtinen <petri@digip.org>
Wed, 4 Nov 2009 20:10:46 +0000 (22:10 +0200)
Conflicts:
test/.gitignore
test/testprogs/Makefile.am

src/load.c
test/.gitignore
test/testdata/invalid
test/testdata/invalid-strip
test/testprogs/Makefile.am
test/testprogs/test_load.c [new file with mode: 0644]

index f004525..1ae62b3 100644 (file)
@@ -418,11 +418,15 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error)
             goto out;
         }
     }
-    else /* c != '0' */ {
+    else if(isdigit(c)) {
         c = lex_get_save(lex, error);
         while(isdigit(c))
             c = lex_get_save(lex, error);
     }
+    else {
+      lex_unget_unsave(lex, c);
+      goto out;
+    }
 
     if(c != '.' && c != 'E' && c != 'e') {
         long value;
@@ -864,6 +868,8 @@ json_t *json_load_file(const char *path, json_error_t *error)
     json_t *result;
     FILE *fp;
 
+    error_init(error);
+
     fp = fopen(path, "r");
     if(!fp)
     {
index 6f12c1f..1999944 100644 (file)
@@ -4,6 +4,7 @@ load_file_dump_file
 testlogs
 testprogs/test_array
 testprogs/test_dump
+testprogs/test_load
 testprogs/test_number
 testprogs/test_object
 testprogs/test_simple
index 1a70422..7fede67 100644 (file)
@@ -167,7 +167,22 @@ too big negative integer near '-123123123123123'
 ====
 1
 invalid token near 'troo'
-==== invalid-escap ====
+==== minus-sign-without-number ====
+[-foo]
+====
+1
+invalid token near '-'
+==== invalid-negative-integerr ====
+[-123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-negative-real ====
+[-123.123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-escape ====
 ["\a <-- invalid escape"]
 ====
 1
index 8b4a574..1efdc25 100644 (file)
@@ -167,7 +167,22 @@ too big negative integer near '-123123123123123'
 ====
 1
 invalid token near 'troo'
-==== invalid-escap ====
+==== minus-sign-without-number ====
+[-foo]
+====
+1
+invalid token near '-'
+==== invalid-negative-integerr ====
+[-123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-negative-real ====
+[-123.123foo]
+====
+1
+']' expected near 'foo'
+==== invalid-escape ====
 ["\a <-- invalid escape"]
 ====
 1
index 792196a..308b9a5 100644 (file)
@@ -1,7 +1,8 @@
-check_PROGRAMS = test_array test_dump test_simple test_number test_object
+check_PROGRAMS = test_array test_dump test_load test_simple test_number test_object
 
 test_array_SOURCES = test_array.c util.h
 test_dump_SOURCES = test_dump.c util.h
+test_load_SOURCES = test_load.c util.h
 test_simple_SOURCES = test_simple.c util.h
 test_number_SOURCES = test_number.c util.h
 test_object_SOURCES = test_object.c util.h
diff --git a/test/testprogs/test_load.c b/test/testprogs/test_load.c
new file mode 100644 (file)
index 0000000..4d8fa88
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#include <jansson.h>
+#include <string.h>
+#include "util.h"
+
+int main()
+{
+    json_t *json;
+    json_error_t error;
+
+    json = json_load_file("/path/to/nonexistent/file.json", &error);
+    if(error.line != -1)
+        fail("json_load_file returned an invalid line number");
+    if(strcmp(error.text, "unable to open /path/to/nonexistent/file.json: No such file or directory") != 0)
+        fail("json_load_file returned an invalid error message");
+
+    return 0;
+}