preprocess icon indicating copy to clipboard operation
preprocess copied to clipboard

@exec parameters are not parsed correctly

Open anseki opened this issue 8 years ago • 2 comments

The string parameters that include the quotes or commas are not parsed correctly.

For example:

var src = 'foo\n<!-- @exec FNC(' +
  'param1, ' +                            // 0. bare string
  '\'param2\', ' +                        // 1. quoted plain string
  '\'Click "START" button.\', ' +         // 2. double-quotes in single-quotes
  '"Click \'START\' button.", ' +         // 3. single-quotes in double-quotes
  '\'Thu, 09 Jul 2015\', ' +              // 4. comma in quoted string
  '\'Say "1, 2, 3".\', ' +                // 5. comma in quoted string in quoted string
  '\'Click "START", and select one.\'' +  // 6. comma next of quote
  ') -->\nbar';

console.log('==== SRC: ' + src);
console.log('==== RES: ' +
  require('preprocess').preprocess(src, {
    FNC : function() {
      // List all arguments
      return Array.prototype.slice.call(arguments)
        .map(function(arg, i) { return i + ': <' + arg + '>'; }).join('\n');
    },
    param1: 'p1'
  })
);

Result:

==== SRC: foo
<!-- @exec FNC(param1, 'param2', 'Click "START" button.', "Click 'START' button.", 'Thu, 09 Jul 2015', 'Say "1, 2, 3".', 'Click "START", and select one.') -->
bar
==== RES: foo
0: <p1>
1: <param2>
2: <Click "START" button.>
3: <Click 'START' button.>
4: <undefined>
5: <undefined>
6: <undefined>
7: <undefined>
8: <undefined>
9: <Click "START>
10: <undefined>
bar

0, 1, 2, 3 are OK. But others are not and number of parameters is incorrect.

Result by fixed code:

==== SRC: foo
<!-- @exec FNC(param1, 'param2', 'Click "START" button.', "Click 'START' button.", 'Thu, 09 Jul 2015', 'Say "1, 2, 3".', 'Click "START", and select one.') -->
bar
==== RES: foo
0: <p1>
1: <param2>
2: <Click "START" button.>
3: <Click 'START' button.>
4: <Thu, 09 Jul 2015>
5: <Say "1, 2, 3".>
6: <Click "START", and select one.>
bar

anseki avatar Jul 09 '15 14:07 anseki