Skip to content

Commit

Permalink
Squashed 'src/univalue/' changes from 5839ac3..2740c4f
Browse files Browse the repository at this point in the history
2740c4f Merge branch '2015_11_escape_plan' into bitcoin
7482163 Add new testcase to Makefile.am
46098ee Version 1.0.1.
ccf3575 parser: Ensure multiple values cannot follow each other
eb6cd64 Omit Obj/Arr open token from jsonTokenIsValue() test
bfef9e2 Makefile.am: list recently added test data, fail{35,36}.json
3e319f3 parser: Tighten array, object syntax checks.
c74185c parser: transform C++ variables into bitmask
f2568bc Prefer C++ STL vector .at() for accessing object values.
8eafa26 travis: run parallel 'make distcheck'
fd448da test: Improve tester diagnostics.  Add failing test case from #15
2158205 Use internal, locale-independent isspace(), isdigit() implementations.
2ab9ad4 travis: Make 'make distcheck' for more comprehensive checks.
3339191 Escape all control characters

git-subtree-dir: src/univalue
git-subtree-split: 2740c4f71242086a7eb3dc32f812546ba9fad913
  • Loading branch information
MarcoFalke committed Dec 2, 2015
1 parent 313e7f5 commit 9827091
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ univalue-config.h*
test-driver
libtool
ltmain.sh
test-suite.log

*.a
*.la
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ script:
- ./configure --cache-file=config.cache $UNIVALUE_CONFIG_ALL $UNIVALUE_CONFIG || ( cat config.log && false)
- make -s $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL ; false )
- export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib
- if [ "$RUN_TESTS" = "true" ]; then make check; fi
- if [ "$RUN_TESTS" = "true" ]; then make $MAKEJOBS distcheck; fi

matrix:
fast_finish: true
Expand Down
6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ TEST_FILES = \
$(TEST_DATA_DIR)/fail32.json \
$(TEST_DATA_DIR)/fail33.json \
$(TEST_DATA_DIR)/fail34.json \
$(TEST_DATA_DIR)/fail35.json \
$(TEST_DATA_DIR)/fail36.json \
$(TEST_DATA_DIR)/fail37.json \
$(TEST_DATA_DIR)/fail3.json \
$(TEST_DATA_DIR)/fail4.json \
$(TEST_DATA_DIR)/fail5.json \
Expand All @@ -79,6 +82,7 @@ TEST_FILES = \
$(TEST_DATA_DIR)/fail9.json \
$(TEST_DATA_DIR)/pass1.json \
$(TEST_DATA_DIR)/pass2.json \
$(TEST_DATA_DIR)/pass3.json
$(TEST_DATA_DIR)/pass3.json \
$(TEST_DATA_DIR)/round1.json

EXTRA_DIST=$(TEST_FILES) $(GEN_SRCS)
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ m4_define([libunivalue_age], [m4_eval(libunivalue_binary_age - libunivalue_inter
m4_define([libunivalue_version], [libunivalue_major_version().libunivalue_minor_version().libunivalue_micro_version()libunivalue_extraversion()])


AC_INIT([univalue], [1.0.0],
AC_INIT([univalue], [1.0.1],
[http://github.com/jgarzik/univalue/])

dnl make the compilation flags quiet unless V=1 is used
Expand Down
15 changes: 11 additions & 4 deletions gen/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,32 @@
// $ ./gen > univalue_escapes.h
//

#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "univalue.h"

using namespace std;

static bool initEscapes;
static const char *escapes[256];
static std::string escapes[256];

static void initJsonEscape()
{
// Escape all lower control characters (some get overridden with smaller sequences below)
for (int ch=0x00; ch<0x20; ++ch) {
char tmpbuf[20];
snprintf(tmpbuf, sizeof(tmpbuf), "\\u%04x", ch);
escapes[ch] = std::string(tmpbuf);
}

escapes[(int)'"'] = "\\\"";
escapes[(int)'\\'] = "\\\\";
escapes[(int)'\b'] = "\\b";
escapes[(int)'\f'] = "\\f";
escapes[(int)'\n'] = "\\n";
escapes[(int)'\r'] = "\\r";
escapes[(int)'\t'] = "\\t";
escapes[(int)'\x7f'] = "\\u007f"; // U+007F DELETE

initEscapes = true;
}
Expand All @@ -39,13 +46,13 @@ static void outputEscape()
"static const char *escapes[256] = {\n");

for (unsigned int i = 0; i < 256; i++) {
if (!escapes[i]) {
if (escapes[i].empty()) {
printf("\tNULL,\n");
} else {
printf("\t\"");

unsigned int si;
for (si = 0; si < strlen(escapes[i]); si++) {
for (si = 0; si < escapes[i].size(); si++) {
char ch = escapes[i][si];
switch (ch) {
case '"':
Expand Down
35 changes: 34 additions & 1 deletion include/univalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,41 @@ extern enum jtokentype getJsonToken(std::string& tokenVal,
unsigned int& consumed, const char *raw);
extern const char *uvTypeName(UniValue::VType t);

static inline bool jsonTokenIsValue(enum jtokentype jtt)
{
switch (jtt) {
case JTOK_KW_NULL:
case JTOK_KW_TRUE:
case JTOK_KW_FALSE:
case JTOK_NUMBER:
case JTOK_STRING:
return true;

default:
return false;
}

// not reached
}

static inline bool json_isspace(int ch)
{
switch (ch) {
case 0x20:
case 0x09:
case 0x0a:
case 0x0d:
return true;

default:
return false;
}

// not reached
}

extern const UniValue NullUniValue;

const UniValue& find_value( const UniValue& obj, const std::string& name);

#endif // __UNIVALUE_H__
#endif // __UNIVALUE_H__
21 changes: 8 additions & 13 deletions lib/univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <stdint.h>
#include <ctype.h>
#include <errno.h>
#include <iomanip>
#include <limits>
Expand All @@ -21,7 +20,7 @@ static bool ParsePrechecks(const std::string& str)
{
if (str.empty()) // No empty string allowed
return false;
if (str.size() >= 1 && (isspace(str[0]) || isspace(str[str.size()-1]))) // No padding allowed
if (str.size() >= 1 && (json_isspace(str[0]) || json_isspace(str[str.size()-1]))) // No padding allowed
return false;
if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
return false;
Expand Down Expand Up @@ -210,7 +209,7 @@ bool UniValue::pushKVs(const UniValue& obj)

for (unsigned int i = 0; i < obj.keys.size(); i++) {
keys.push_back(obj.keys[i]);
values.push_back(obj.values[i]);
values.push_back(obj.values.at(i));
}

return true;
Expand All @@ -234,7 +233,7 @@ bool UniValue::checkObject(const std::map<std::string,UniValue::VType>& t)
if (idx < 0)
return false;

if (values[idx].getType() != it->second)
if (values.at(idx).getType() != it->second)
return false;
}

Expand All @@ -250,7 +249,7 @@ const UniValue& UniValue::operator[](const std::string& key) const
if (index < 0)
return NullUniValue;

return values[index];
return values.at(index);
}

const UniValue& UniValue::operator[](unsigned int index) const
Expand All @@ -260,7 +259,7 @@ const UniValue& UniValue::operator[](unsigned int index) const
if (index >= values.size())
return NullUniValue;

return values[index];
return values.at(index);
}

const char *uvTypeName(UniValue::VType t)
Expand All @@ -278,15 +277,11 @@ const char *uvTypeName(UniValue::VType t)
return NULL;
}

const UniValue& find_value( const UniValue& obj, const std::string& name)
const UniValue& find_value(const UniValue& obj, const std::string& name)
{
for (unsigned int i = 0; i < obj.keys.size(); i++)
{
if( obj.keys[i] == name )
{
return obj.values[i];
}
}
if (obj.keys[i] == name)
return obj.values.at(i);

return NullUniValue;
}
Expand Down
56 changes: 28 additions & 28 deletions lib/univalue_escapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@
#ifndef BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H
#define BITCOIN_UNIVALUE_UNIVALUE_ESCAPES_H
static const char *escapes[256] = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
"\\u0000",
"\\u0001",
"\\u0002",
"\\u0003",
"\\u0004",
"\\u0005",
"\\u0006",
"\\u0007",
"\\b",
"\\t",
"\\n",
NULL,
"\\u000b",
"\\f",
"\\r",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
"\\u000e",
"\\u000f",
"\\u0010",
"\\u0011",
"\\u0012",
"\\u0013",
"\\u0014",
"\\u0015",
"\\u0016",
"\\u0017",
"\\u0018",
"\\u0019",
"\\u001a",
"\\u001b",
"\\u001c",
"\\u001d",
"\\u001e",
"\\u001f",
NULL,
NULL,
"\\\"",
Expand Down Expand Up @@ -129,7 +129,7 @@ static const char *escapes[256] = {
NULL,
NULL,
NULL,
NULL,
"\\u007f",
NULL,
NULL,
NULL,
Expand Down
Loading

0 comments on commit 9827091

Please sign in to comment.