Skip to content

"TypeError: v is null" when parsing numbers with exponent #44

Description

@h3ndrk

Thanks for the great library! I found a bug in the graph writer:

Consider a graph with a node attribute x=-1.4703333520951247e-16, when writing and reading the same graph, graphlib-dot yields TypeError: v is null in peg$c34:

var dot = require('graphlib-dot');
var graphlib = require('graphlib');

// prepare graph
var graph = new graphlib.Graph({directed: false});
graph.setNode(42, { x: -1.4703333520951247e-16 });

// show output
dot.write(graph); // -> 'strict graph {\n  "42" [x=-1.4703333520951247e-16]\n}\n'

// trigger TypeError
dot.read(dot.write(graph));
// Uncaught TypeError: Cannot read property '3' of null
//     at peg$c34 (node_modules/graphlib-dot/lib/dot-grammar.js:114:28)
//     at peg$parseidDef (node_modules/graphlib-dot/lib/dot-grammar.js:1421:16)
//     at peg$parseaList (node_modules/graphlib-dot/lib/dot-grammar.js:1173:20)
//     at peg$parseattrListBlock (node_modules/graphlib-dot/lib/dot-grammar.js:1093:16)
//     at peg$parseattrList (node_modules/graphlib-dot/lib/dot-grammar.js:1012:12)
//     at peg$parsenodeStmt (node_modules/graphlib-dot/lib/dot-grammar.js:808:16)
//     at peg$parsestmt (node_modules/graphlib-dot/lib/dot-grammar.js:689:20)
//     at peg$parsestmtList (node_modules/graphlib-dot/lib/dot-grammar.js:538:12)
//     at peg$parsegraphStmt (node_modules/graphlib-dot/lib/dot-grammar.js:452:28)
//     at Object.parse (node_modules/graphlib-dot/lib/dot-grammar.js:2372:18)

I think dot.write() produces a non-compliant string (because the ID is not allowed to have a dash -). The parser looks fine.

I'm using graphlib-dot@0.6.4.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions