🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

toml

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toml - npm Package Compare versions

Comparing version

to
2.3.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

2.3.0 - July 13 2015
====================
* Correctly handle quoted keys ([#21](https://github.com/BinaryMuse/toml-node/issues/21))
2.2.3 - June 8 2015

@@ -2,0 +7,0 @@ ===================

34

lib/compiler.js

@@ -94,11 +94,10 @@ function compile(nodes) {

var path = node.value;
var quotedPath = path.map(quoteDottedString).join(".");
var line = node.line;
var column = node.column;
checkPath(path, line, column);
if (pathAssigned(path)) {
if (pathAssigned(quotedPath)) {
genError("Cannot redefine existing key '" + path + "'.", line, column);
}
assignedPaths.push(path);
assignedPaths.push(quotedPath);
context = deepRef(data, path, {}, line, column);

@@ -110,16 +109,15 @@ currentPath = path;

var path = node.value;
var quotedPath = path.map(quoteDottedString).join(".");
var line = node.line;
var column = node.column;
checkPath(path, line, column);
if (!pathAssigned(path)) {
assignedPaths.push(path);
if (!pathAssigned(quotedPath)) {
assignedPaths.push(quotedPath);
}
assignedPaths = assignedPaths.filter(function(p) {
return p.indexOf(path) !== 0;
return p.indexOf(quotedPath) !== 0;
});
assignedPaths.push(path);
assignedPaths.push(quotedPath);
context = deepRef(data, path, [], line, column);
currentPath = path;
currentPath = quotedPath;

@@ -139,7 +137,7 @@ if (context instanceof Array) {

// array is used as the context for the next sub-path.
function deepRef(start, path, value, line, column) {
function deepRef(start, keys, value, line, column) {
var key;
var traversed = [];
var traversedPath = "";
var keys = path.split(".");
var path = keys.join(".");
var ctx = start;

@@ -191,7 +189,7 @@ var keysLen = keys.length;

function checkPath(path, line, column) {
if (path[0] === ".") {
genError("Cannot start a table key with '.'.", line, column);
} else if (path[path.length - 1] === ".") {
genError("Cannot end a table key with '.'.", line, column);
function quoteDottedString(str) {
if (str.indexOf(".") > -1) {
return "\"" + str + "\"";
} else {
return str;
}

@@ -198,0 +196,0 @@ }

{
"name": "toml",
"version": "2.2.3",
"version": "2.3.0",
"description": "TOML parser for Node.js (parses TOML spec v0.4.0)",

@@ -5,0 +5,0 @@ "main": "index.js",

var toml = require('../');
var fs = require('fs');
var assert = require("nodeunit").assert;
assert.parsesToml = function(tomlStr, expected) {
try {
var actual = toml.parse(tomlStr);
} catch (e) {
var errInfo = "line: " + e.line + ", column: " + e.column;
return assert.fail("TOML parse error: " + e.message, errInfo, null, "at", assert.parsesToml);
}
return assert.deepEqual(actual, expected);
};
var exampleExpected = {

@@ -99,3 +111,3 @@ title: "TOML Example",

var str = fs.readFileSync(__dirname + "/example.toml", 'utf-8')
test.deepEqual(toml.parse(str), exampleExpected);
test.parsesToml(str, exampleExpected);
test.done();

@@ -106,3 +118,3 @@ };

var str = fs.readFileSync(__dirname + "/hard_example.toml", 'utf-8')
test.deepEqual(toml.parse(str), hardExampleExpected);
test.parsesToml(str, hardExampleExpected);
test.done();

@@ -113,3 +125,3 @@ };

var str = fs.readFileSync(__dirname + "/table_arrays_easy.toml", 'utf8')
test.deepEqual(toml.parse(str), easyTableArrayExpected);
test.parsesToml(str, easyTableArrayExpected);
test.done();

@@ -120,3 +132,3 @@ };

var str = fs.readFileSync(__dirname + "/table_arrays_hard.toml", 'utf8')
test.deepEqual(toml.parse(str), hardTableArrayExpected);
test.parsesToml(str, hardTableArrayExpected);
test.done();

@@ -128,4 +140,3 @@ };

var expected = { arr: [1, 2, 3] };
var results = toml.parse(str);
test.deepEqual(results, expected);
test.parsesToml(str, expected);
test.done();

@@ -136,3 +147,3 @@ };

var str = "a = [1]";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
a: [1]

@@ -145,3 +156,3 @@ });

var str = "a = []";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
a: []

@@ -154,3 +165,3 @@ });

var str = "[versions]\nfiles = [\n 3, \n 5 \n\n ]";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
versions: {

@@ -165,3 +176,3 @@ files: [3, 5]

var str = "[versions]\nfiles = [\n \n ]";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
versions: {

@@ -184,3 +195,3 @@ files: []

};
test.deepEqual(toml.parse(str), expected);
test.parsesToml(str, expected);
test.done();

@@ -191,3 +202,3 @@ };

var str = "a = 1\n \n b = 2 ";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
a: 1, b: 2

@@ -200,3 +211,3 @@ });

var str = "str = \"My name is Jos\\u00E9\"";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
str: "My name is Jos\u00E9"

@@ -206,3 +217,3 @@ });

var str = "str = \"My name is Jos\\U000000E9\"";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
str: "My name is Jos\u00E9"

@@ -215,3 +226,3 @@ });

var str = fs.readFileSync(__dirname + "/multiline_strings.toml", 'utf8');
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
key1: "One\nTwo",

@@ -226,3 +237,3 @@ key2: "One\nTwo",

var str = fs.readFileSync(__dirname + "/multiline_eat_whitespace.toml", 'utf8');
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
key1: "The quick brown fox jumps over the lazy dog.",

@@ -237,3 +248,3 @@ key2: "The quick brown fox jumps over the lazy dog.",

var str = fs.readFileSync(__dirname + "/literal_strings.toml", 'utf8');
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
winpath: "C:\\Users\\nodejs\\templates",

@@ -249,3 +260,3 @@ winpath2: "\\\\ServerX\\admin$\\system32\\",

var str = fs.readFileSync(__dirname + "/multiline_literal_strings.toml", 'utf8');
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
regex2: "I [dw]on't need \\d{2} apples",

@@ -259,3 +270,3 @@ lines: "The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n"

var str = "a = +99\nb = 42\nc = 0\nd = -17\ne = 1_000_001\nf = 1_2_3_4_5 # why u do dis";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
a: 99,

@@ -277,3 +288,3 @@ b: 42,

"i = 1e1_000";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
a: 1.0,

@@ -294,3 +305,3 @@ b: 3.1415,

var date = new Date("1979-05-27T07:32:00Z");
test.deepEqual(toml.parse("a = 1979-05-27T07:32:00Z"), {
test.parsesToml("a = 1979-05-27T07:32:00Z", {
a: date

@@ -304,3 +315,3 @@ });

date2 = new Date("1979-05-27T07:32:00+02:00");
test.deepEqual(toml.parse("a = 1979-05-27T07:32:00-07:00\nb = 1979-05-27T07:32:00+02:00"), {
test.parsesToml("a = 1979-05-27T07:32:00-07:00\nb = 1979-05-27T07:32:00+02:00", {
a: date1,

@@ -314,3 +325,3 @@ b: date2

var date = new Date("1979-05-27T00:32:00.999999-07:00");
test.deepEqual(toml.parse("a = 1979-05-27T00:32:00.999999-07:00"), {
test.parsesToml("a = 1979-05-27T00:32:00.999999-07:00", {
a: date

@@ -327,3 +338,3 @@ });

test.deepEqual(toml.parse(tomlStr), {
test.parsesToml(tomlStr, {
a: date

@@ -337,3 +348,3 @@ });

var str = "\ntest = \"ing\"";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
test: "ing"

@@ -345,5 +356,4 @@ });

exports.testInlineTables = function(test) {
var str = fs.readFileSync(__dirname + "/inline_tables.toml", 'utf8'),
parsed = toml.parse(str);
test.deepEqual(parsed, {
var str = fs.readFileSync(__dirname + "/inline_tables.toml", 'utf8');
test.parsesToml(str, {
name: {

@@ -380,3 +390,3 @@ first: "Tom",

var str = "a = { }";
test.deepEqual(toml.parse(str), {
test.parsesToml(str, {
a: {}

@@ -387,2 +397,99 @@ });

exports.testKeyNamesWithWhitespaceAroundStartAndFinish = function(test) {
var str = "[ a ]\nb = 1";
test.parsesToml(str, {
a: {
b: 1
}
});
test.done();
};
exports.testKeyNamesWithWhitespaceAroundDots = function(test) {
var str = "[ a . b . c]\nd = 1";
test.parsesToml(str, {
a: {
b: {
c: {
d: 1
}
}
}
});
test.done();
};
exports.testSimpleQuotedKeyNames = function(test) {
var str = "[\"ʞ\"]\na = 1";
test.parsesToml(str, {
"ʞ": {
a: 1
}
});
test.done();
};
exports.testComplexQuotedKeyNames = function(test) {
var str = "[ a . \"ʞ\" . c ]\nd = 1";
test.parsesToml(str, {
a: {
"ʞ": {
c: {
d: 1
}
}
}
});
test.done();
};
exports.testEscapedQuotesInQuotedKeyNames = function(test) {
test.parsesToml("[\"the \\\"thing\\\"\"]\na = true", {
'the "thing"': {
a: true
}
});
test.done();
};
exports.testMoreComplexQuotedKeyNames = function(test) {
// https://github.com/BinaryMuse/toml-node/issues/21
test.parsesToml('["the\\ key"]\n\none = "one"\ntwo = 2\nthree = false', {
"the\\ key": {
one: "one",
two: 2,
three: false
}
});
test.parsesToml('[a."the\\ key"]\n\none = "one"\ntwo = 2\nthree = false', {
a: {
"the\\ key": {
one: "one",
two: 2,
three: false
}
}
});
test.parsesToml('[a."the-key"]\n\none = "one"\ntwo = 2\nthree = false', {
a: {
"the-key": {
one: "one",
two: 2,
three: false
}
}
});
test.parsesToml('[a."the.key"]\n\none = "one"\ntwo = 2\nthree = false', {
a: {
"the.key": {
one: "one",
two: 2,
three: false
}
}
});
test.done();
};
exports.testErrorOnBadUnicode = function(test) {

@@ -389,0 +496,0 @@ var str = "str = \"My name is Jos\\uD800\"";

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet