JimLiu / bbcode-to-react

A utility for turning raw BBCode into React elements.
MIT License
24 stars 21 forks source link

Uncaught TypeError: Cannot read property '0' of undefined #12

Open TanninOne opened 6 years ago

TanninOne commented 6 years ago

When parsing tags this code entirely relies on a parse result:

let params = this.parseParams(token.slice(1, -1));
let tagName = params[0][0].toLowerCase();

However parseParam will return an empty array for empty tags or tags that start with on, because of this

      if (name) {
        const n = name.trim();
        // ignore on* events attribute
        if (n.length && n.toLowerCase().indexOf('on') !== 0) {
          params.push([n, value]);
        }
      }

Now "[ ]" is used for example by github for an empty checkbox, [on...] could be all kind of things, both are valid and shouldn't cause the parser to throw an exception.

dainiusgliebus commented 5 years ago

Would be nice if this issue can be fixed