Lellansin / node-scanf

C like scanf module for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Special characters not escaped in `sscanf`

trichner opened this issue · comments

I'm using sscanf(data,'a[%x]', 'address') to parse the string a[1A] and get the following error:

error:  SyntaxError: Invalid regular expression: /a[([A-Za-z0-9]+)/: Unmatched ')'
    at new RegExp (<anonymous>)
    at getInput (/home/trichner/workspace/mac-visualization/node_modules/scanf/lib/scanf.js:72:23)
    at getHex (/home/trichner/workspace/mac-visualization/node_modules/scanf/lib/scanf.js:107:14)
    at dealType (/home/trichner/workspace/mac-visualization/node_modules/scanf/lib/scanf.js:153:13)
    at Object.module.exports (/home/trichner/workspace/mac-visualization/node_modules/scanf/lib/scanf.js:39:14)
    at scanf.sscanf (/home/trichner/workspace/mac-visualization/node_modules/scanf/lib/scanf.js:57:16)

I suspect sscanf substitutes my %x with the appropriate regex but does not properly escape my [ and ].

Thanks a lot for your feedback. I'm very sorry to reply so late. I'v fix this at b9bfecf.

and this is the test:

it('a[%x]', function(done) {
  var str = "a[1A]";
  var result = sscanf(str,'a[%x]', 'address');
  should.deepEqual(result, {
    address: 26
  });
    done();
});